<?php

//require_once("module.php");
require_once(dirname(__FILE__)."/../../../system/libraries/module.php");
require_once(dirname(__FILE__)."/../../../system/libraries/node.php");


class Main extends Controller {
	
	
	public $userId = 0; //2;
	
	
	public $drzewo = '';
	
	public $main_url = '';
	
	public $adres = '';
	public $folder = '';
	public $strona = '';
	
	public $podstrona = '';
	public $podstrona_dane = NULL;
	
	public $szukaj = '';
	
	public $lang_nr;
	public $lang_code;
	
	public $templateId = -1;
	
	public $mainId = 0;
	public $mainName = '';
	
	function Main()
	{
		parent::Controller();
		
		$this->load->helper('url');
		$this->load->helper('text');
		$this->load->helper('security');
		
		$this->load->library('session');
		
		$this->main_url = $this->config->item('main_url');
		$this->lang_nr = '';
		$this->lang_code = '';
		
		
		$query = $this->db->get_where('users', array('ID_users !=' => 1, 'user_admin !=' => 1));
		$this->userId = $query->row()->ID_users;
		

		$request = parse_url($_SERVER['REQUEST_URI']);
		if(array_key_exists('query', $request)){
			parse_str($request['query'], $requestQ);
			if(array_key_exists('szukaj', $requestQ)){
				$this->szukaj = strip_tags(quotes_to_entities(xss_clean($requestQ['szukaj'])));
			}
		}
		
		
		$this->load->library('template');
		$this->load->library('messages');
		$this->load->model('User_model');
		
		$q = '';
		$a = parse_url($_SERVER['REQUEST_URI']);
		if(array_key_exists('query', $a)){
			parse_str($a['query'], $a);
			if(array_key_exists('t', $a)){
				$q = $a['t'];
				$this->templateId = $q;
				$this->session->set_userdata(array(
					'templateId' => $q,
					'template' => true
				));
			}
		} else {
			if($this->session->userdata('template') == true){
				$this->templateId = $this->session->userdata('templateId');
			}
		}
		
		$this->load->model('../../../system/application/models/Tree_model');
		$root = new node($this->Tree_model, $this->Tree_model->getRootId($this->userId));
		$nodes = $root->getNodeFirtLevelChilds();
		
		$mainId = 0;
		$mainName = '';
		$c = count($nodes);
		//foreach($nodes as $singleNode){
		for($i = 0; $i < $c; $i++){
			$singleNode = $nodes[$i];
			if($singleNode->nodeData['published'] == 1){
				$mainId = $singleNode->id;
				$mainName = $singleNode->nodeData['name_url'];//url_title($singleNode->nodeData['name']);
				break;
			}
		}
		$this->mainId = $mainId;
		$this->mainName = $mainName;
		
		//echo $this->templateId;
	}
	
	function index(/*$userId = 0,*/ $lang_code = 'pl')
	{	
		//if($userId == 0) redirect(prep_url($_SERVER['HTTP_HOST']));
		//$this->userId = $userId;
		$this->adres = $this->User_model->getpagename($this->userId);
		
		if($lang_code == 'pl') $this->lang_code = '';
		else $this->lang_code = $lang_code;
		$this->lang_nr = $this->User_model->getlang($this->userId, $lang_code);
		if($this->lang_nr == -1) redirect(prep_url($this->adres).'');
		
		//$this->userId = $userId;
		//$this->output->cache(10);
		
		//$data['main_url'] = $this->main_url;
		//$data['userId'] = $this->userId;
		$this->load->model('../../../system/application/models/Tree_model');
		//$rootId = $this->Tree_model->getRootId($userId);
		$root = new node($this->Tree_model, $this->Tree_model->getRootId($this->userId));
		$nodes = $root->getNodeFirtLevelChilds();
		
		$mainId = 0;
		$mainName = '';
		$c = count($nodes);
		//foreach($nodes as $singleNode){
		for($i = 0; $i < $c; $i++){
			$singleNode = $nodes[$i];
			if($singleNode->nodeData['published'] == 1){
				$mainId = $singleNode->id;
				$mainName = $singleNode->nodeData['name_url'];//url_title($singleNode->nodeData['name']);
				break;
			}
		}
		$this->page(/*$this->userId,*/ $lang_code, $mainId, $mainName);
	}
	
	private function displayTree($rootNode) {
		$node = clone $rootNode;
		if(!$node->getNodeChildsCount()) return;
		$nodes = $node->getNodeFirtLevelChilds();
	
		if($node->path=="root") $this->drzewo.= "<ul class='jd_menu'>"; else 	$this->drzewo.= "<ul class='level2'>";
			
		//foreach($nodes as $singleNode) {
		$c = count($nodes);
		for($i = 0; $i < $c; $i++){	
			$singleNode = $nodes[$i];
			if(/*$singleNode->nodeData['published'] == 1 &&*/ $singleNode->nodeData['menu'] == 1){
				if($this->lang_code == '') $lang_code=$this->lang_code; else $lang_code='/'.$this->lang_code;
				if($singleNode->nodeData['name_url'] == $this->strona) $active = ' active'; else $active='';
				if($singleNode->getNodeChildsCount()) $isNextLevel="class='accessible ".$active."'"; else $isNextLevel="class='".$active."'";
				
				if($singleNode->nodeData['link'] == 1) $href = prep_url($singleNode->nodeData['link_val']); else $href = prep_url($this->adres).$lang_code."/".$singleNode->nodeData['name_url'];
				$this->drzewo.= "<li><a href='".$href."' ".$isNextLevel." title='".$singleNode->nodeData['title']."' >".$singleNode->nodeData['name']."</a>";
				$clodeNode = clone $singleNode;
				$this->displayTree($clodeNode);
				$this->drzewo.= "</li>";
			}
		}
		$this->drzewo.= "</ul>";
	}
	
	private function treeToArray($rootNode){
		$tab = array();
		$node = clone $rootNode;
		if(!$node->getNodeChildsCount()) return NULL;
		$nodes = $node->getNodeFirtLevelChilds();
		
		//foreach($nodes as $singleNode){
		$c = count($nodes);
		for($i = 0; $i < $c; $i++){
			$singleNode = $nodes[$i];
			if(/*$singleNode->nodeData['published'] == 1 &&*/ $singleNode->nodeData['menu'] == 1){
				$arrayNode = array(
					'name' => $singleNode->nodeData['name'],
					'name_url' => $singleNode->nodeData['name_url'],
					'link' => $singleNode->nodeData['link'],
					'link_val' => $singleNode->nodeData['link_val'],
					'tree' => $this->treeToArray($singleNode)
				);
				
				array_push($tab, $arrayNode);
			}
		}		
		
		return $tab;
	}
	
	private function treeToArray1($rootNode){
		$tab = array();
		$node = clone $rootNode;
		if(!$node->getNodeChildsCount()) return NULL;
		$nodes = $node->getNodeFirtLevelChilds();
		
		//foreach($nodes as $singleNode){
		$c = count($nodes);
		for($i = 0; $i< $c; $i++){
			$singleNode = $nodes[$i];
			if(/*$singleNode->nodeData['published'] == 1 &&*/ $singleNode->nodeData['menu'] == 1){
				$arrayNode = array(
					'name' => $singleNode->nodeData['name'],
					'name_url' => $singleNode->nodeData['name_url'],
					'link' => $singleNode->nodeData['link'],
					'link_val' => $singleNode->nodeData['link_val'],
					'tree' => $this->treeToArray($singleNode)
				);
				array_push($tab, $arrayNode);
			}			
		}		
		
		return $tab;
	}
	
	private function RecurseArray( $inarray, $toarray, $template, $dir) { 
		foreach ( $inarray as $inkey => $inval ) { 
			if ( is_array( $inval ) ) { 
				$toarray = $this->RecurseArray( $inval, $toarray, $template, $dir.'/'.$inkey); 
			} else { 
				$toarray[] = $inval; 

				$r=explode(".",$inval);
				$ext=$r[count($r)-1];
				//echo $dir.$inval;
				if($ext == "js")	$template->add_js($dir.'/'.$inval, $type = 'import', $defer = FALSE);
				if($ext == "css")	$template->add_css($dir.'/'.$inval);
			} 
		}
		return $toarray; 
	}
	
	function page(/*$userId,*/ $lang_code, $id, $name, $name2 = '') {
		$name_copy = $name; 
		$data['active'] = $name;
		$data['active2'] = $name2;
		
		if($name2 != '') $name = $name2;
		
		//$this->userId = $userId;
		$this->adres = $this->User_model->getpagename($this->userId);
		
		if($lang_code == 'pl') $this->lang_code = '';
		else $this->lang_code = $lang_code;
		$this->lang_nr = $this->User_model->getlang($this->userId, $lang_code);
		if($this->lang_nr == -1) redirect(prep_url($this->adres).'');
		//$data['main_url'] = $this->main_url;
	
		$this->load->model('../../../system/application/models/Tree_model');
		
		$this->adres = $this->User_model->getpagename($this->userId);
		$this->folder = $this->User_model->getfolder($this->userId);
		
		//$data['adres'] = $this->adres;
		
		if($this->User_model->checkblock($this->userId)){
			echo 'Strona zablokowana';
			return;
		}
		
		$rootId = $this->Tree_model->getRootId($this->userId);
		
		$this->strona = $name;
		
		$root = new node($this->Tree_model, $rootId);
		$this->displayTree($root);
		//$data['menu'] = $this->drzewo;
		
		if(($id = $this->User_model->getIdByName($name, $this->userId)) == 0 || $this->User_model->getIdByName($name_copy, $this->userId) == 0){
			//redirect('http://'.$this->adres);
			$root = new node($this->Tree_model, $this->Tree_model->getRootId($this->userId));
			$nodes = $root->getNodeFirtLevelChilds();
			
			$mainId = 0;
			$mainName = '';
			$c = count($nodes);

			for($i = 0; $i < $c; $i++){
				$singleNode = $nodes[$i];
				if($singleNode->nodeData['published'] == 1){
					$mainId = $singleNode->id;
					$mainName = $singleNode->nodeData['name_url'];
					break;
				}
			}
			$id = $mainId;
			$data['active'] = $data['active2'] = $name = $name2 = $mainName;
			$this->strona = $mainName;
		} 
		
		$node = new node($this->Tree_model, $id);
		
		
		$nodess = $root->getNodeFirtLevelChilds();
		$mainId = 0;
		$cc = count($nodess);
		for($i = 0; $i < $cc; $i++){
			$singleNode = $nodess[$i];
			if($singleNode->nodeData['published'] == 1){
				$mainId = $singleNode->id;
				break;
			}
		}
		
		//echo $mainId.' a '.$id;
		//return;
		
		if($node->getNodeChildsCount() > 0 && $node->nodeData['text'] == '' && $node->nodeData['mini'] == 0 && $this->User_model->getModules($id, $this->userId)->num_rows() == 0){
			//echo '1111111';
			$nodes = $node->getNodeFirtLevelChilds();
			foreach($nodes as $n){
				//redirect(reduce_double_slashes(prep_url($this->adres).'/'.$node->nodeData['name_url'].'/'.$n->nodeData['name_url']));
				$this->page(/*$this->userId,*/ $lang_code, $n->id, $node->nodeData['name_url'], $n->nodeData['name_url']);
				return;
			}
		}
		
		$parents = $node->getParentsNodes();
		if(sizeof($parents) > 1) $data['active'] = $parents[sizeof($parents)-2]->nodeData['name_url']; 
		$data['active2'] = $node->nodeData['name_url'];
		
		
		$currentPageName = $node->nodeData['name'];
		
		
		/*
		if($node->nodeData['published']==0){
			$nodes2 = $node->getNodeFirtLevelChilds();
			foreach($nodes2 as $singleNode) {
				$this->page($userId, $singleNode->id, $singleNode->nodeData['name']);
				return;
			}
		}
		*/
		$modules = $this->User_model->getModules($id, $this->userId);
						
		if($this->templateId > -1) {
			$user_template = $this->templateId;
		} else {
			$user_template = $this->User_model->getpagetemplate($this->userId);
		}
		$user_template_folder = $this->User_model->getpagetemplatefolder($user_template);
		
		if($user_template == 0) {
			$base_template = '../../'.$this->folder.'/template/base/';
			$data['base_template'] = reduce_double_slashes(prep_url(base_url($this->adres).'/'));
		}
		else {
			$base_template = '../template/'.$user_template_folder->global_templates_folder.'/';
			$data['base_template'] = reduce_double_slashes(base_url().'application/template/'.$user_template_folder->global_templates_folder.'/');
		}
		
		
		/*if($user_template == 1) $base_template = '../template/base_template_1/';
		if($user_template == 2) $base_template = '../template/base_template_2/';
		if($user_template == 3) $base_template = '../template/base_template_3/';
		if($user_template == 0) $base_template = '../../'.$this->folder.'/template/base/';
		*/
		/*if($node->nodeData['template'] == 1) $template = '../template/content_template_1/content';
		else if($node->nodeData['template'] == 2) $template = '../template/content_template_2/content';
		else if($node->nodeData['template'] == 3) $template = '../template/content_template_3/content';
		else $template = '../../'.$this->folder.'/template/content/'.$node->nodeData['template'];*/
		
		$template_id = $node->nodeData['template'];
		$article_template = $this->User_model->getarticletemplate($template_id);
		$template = '../../../'.trim_slashes($article_template->article_templates_folder).'/'.$article_template->article_templates_filename;
		//echo $article_template->article_templates_name.' '.$node->nodeData['template'];
		
		
		
		/*
		if($user_template == 0){
			if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/tekst.php')){
				$mod_view = '../../'.$this->folder.'/template/tekst';
			} else $mod_view = '../template/tekst';
		} else if($user_template == 1){
			if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/tekst.php')){
				$mod_view = '../../'.$this->folder.'/template/tekst';
			} else $mod_view = '../template/base_template_1/modules/tekst';
		} else if($user_template == 2){
			if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/tekst.php')){
				$mod_view = '../../'.$this->folder.'/template/tekst';
			} else $mod_view = '../template/base_template_2/modules/tekst';
		} else if($user_template == 3){
			if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/tekst.php')){
				$mod_view = '../../'.$this->folder.'/template/tekst';
			} else $mod_view = '../template/base_template_3/modules/tekst';
		}
		*/
		
		/*if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/tekst.php')){
			$mod_view = '../../'.$this->folder.'/template/tekst';
		} else {
			if($user_template == 1){
				$mod_view = '../template/base_template_1/modules/tekst';
			} else if($user_template == 2){
				$mod_view = '../template/base_template_2/modules/tekst';
			} else if($user_template == 3){
				$mod_view = '../template/base_template_3/modules/tekst';
			} else {
				$mod_view = '../template/tekst';
			}
		}*/
		
		
		
		$base['template'] = $base_template.'base.php';
		$base['regions'] = array('head', /*'header',*/ 'menu', 'menuDodatkowe', 'content', 'footer');
		
		$this->template->add_template('base', $base, TRUE);
		
		
		$plugins = $this->User_model->getuserplugins($this->userId);
		
		$this->load->helper('directory');
		
		if($plugins && $plugins->num_rows > 0) foreach($plugins->result() as $plugin){
			if(file_exists(dirname(__FILE__).'/../../plugins/'.$plugin->plugins_katalog)){
				$map = directory_map(dirname(__FILE__).'/../../plugins/'.$plugin->plugins_katalog);
				//print_r($map);
				$this->RecurseArray($map, $map, $this->template, 'plugins/'.$plugin->plugins_katalog);
			}
		}
		
		if(($user_template > 0) && ($user_template_folder != NULL)){
			if(file_exists(dirname(__FILE__).'/../template/'.$user_template_folder->global_templates_folder.'/js')){
				$map = directory_map(dirname(__FILE__).'/../template/'.$user_template_folder->global_templates_folder.'/js');
				$this->RecurseArray($map, $map, $this->template, 'application/template/'.$user_template_folder->global_templates_folder.'/js');
			}
			if(file_exists(dirname(__FILE__).'/../template/'.$user_template_folder->global_templates_folder.'/css')){
				$map = directory_map(dirname(__FILE__).'/../template/'.$user_template_folder->global_templates_folder.'/css');
				$this->RecurseArray($map, $map, $this->template, 'application/template/'.$user_template_folder->global_templates_folder.'/css');
			}
		}
		/*
		if($user_template == 1){
			if(file_exists(dirname(__FILE__).'/../template/base_template_1/js')){
				$map = directory_map(dirname(__FILE__).'/../template/base_template_1/js');
				$this->RecurseArray($map, $map, $this->template, 'application/template/base_template_1/js');
			}
			if(file_exists(dirname(__FILE__).'/../template/base_template_1/css')){
				$map = directory_map(dirname(__FILE__).'/../template/base_template_1/css');
				$this->RecurseArray($map, $map, $this->template, 'application/template/base_template_1/css');
			}
		} else if($user_template == 2){
			if(file_exists(dirname(__FILE__).'/../template/base_template_2/js')){
				$map = directory_map(dirname(__FILE__).'/../template/base_template_2/js');
				$this->RecurseArray($map, $map, $this->template, 'application/template/base_template_2/js');
			}
			if(file_exists(dirname(__FILE__).'/../template/base_template_2/css')){
				$map = directory_map(dirname(__FILE__).'/../template/base_template_2/css');
				$this->RecurseArray($map, $map, $this->template, 'application/template/base_template_2/css');
			}
		} else if($user_template == 3){
			if(file_exists(dirname(__FILE__).'/../template/base_template_3/js')){
				$map = directory_map(dirname(__FILE__).'/../template/base_template_3/js');
				$this->RecurseArray($map, $map, $this->template, 'application/template/base_template_3/js');
			}
			if(file_exists(dirname(__FILE__).'/../template/base_template_3/css')){
				$map = directory_map(dirname(__FILE__).'/../template/base_template_3/css');
				$this->RecurseArray($map, $map, $this->template, 'application/template/base_template_3/css');
			}
		}*/
		
		
		if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/js')){
			$map = directory_map(dirname(__FILE__).'/../../'.$this->folder.'/js');
			$this->RecurseArray($map, $map, $this->template, $this->folder.'/js');
		}
		if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/css')){
			$map = directory_map(dirname(__FILE__).'/../../'.$this->folder.'/css');
			$this->RecurseArray($map, $map, $this->template, $this->folder.'/css');
		}
		
		
		/*
		if($this->lang_nr == '') $data['user'] = $this->Administrator_model->get_user($this->session->userdata('uzytkownik_id'))->row();
		else {
			$user = $this->Administrator_model->get_meta($this->session->userdata('uzytkownik_id'), $this->lang_nr);
			if($user && $user->num_rows() > 0)
				$data['user'] = $user->row();
			else {
				$user->user_title = '';
				$user->user_description = '';
				$data['user'] = $user;
			}
		}
		*/
		
		$this->load->helper('text');
		$headdata = array(
			'title' => $node->nodeData['title']=='' ? ''.$this->User_model->gettitle($this->userId, $this->lang_nr).' - '.$currentPageName : $node->nodeData['title'],
			//'title' => $this->User_model->gettitle($userId, $this->lang_nr)==NULL ? $node->nodeData['title'] : $this->User_model->gettitle($userId, $this->lang_nr).' - '.$currentPageName,
			//'description' => $node->nodeData['description']=='' ? ''.$this->User_model->getdescription($userId, $this->lang_nr).' - '.strip_tags($node->nodeData['text']) : ''.$node->nodeData['description'],
			'description' => strip_tags($node->nodeData['text'])=='' ? ''.$this->User_model->getdescription($this->userId, $this->lang_nr) : ''.character_limiter(strip_tags(strip_quotes($node->nodeData['text'])), 250),
			//'description' => $this->User_model->getdescription($userId, $this->lang_nr)==NULL ? $node->nodeData['description'] : $this->User_model->getdescription($userId, $this->lang_nr),
			'main_url' => $this->main_url,
			'adres' => $this->adres
		);
		$this->template->write_view('head', $base_template.'head', $headdata);
		$this->template->write('menu', $this->drzewo);
		//echo $node->id;
		//print_r(
		$data['currentTree'] = $this->treeToArray($node);
		//);
		$data['menu1'] = $this->treeToArray($root);
		
		$this->drzewo = '';
		$treeId = $this->Tree_model->getMenu2Id($this->userId);
		
		$treeNode = new node($this->Tree_model, $treeId);
		$this->displayTree($treeNode);
		
		//$this->template->write('menuDodatkowe', $this->drzewo);
		$this->template->write('menuDodatkowe', $this->treeToArray($treeNode));
		/*$this->template->write_view('header', $base_template.'header', array('header' => ''//'<h1>'.$node->nodeData['title'].'</h1>'
		));*/																													/****************************************/
		
		//$data['active'] = $name;
		$data['langs'] = $this->User_model->getlangsuser($this->userId);
		
		$data['lang_code'] = $this->lang_code;
		
		$data['menu2'] = $this->treeToArray($treeNode);
		$data['content'] = $node->nodeData['text'];
		$data['name_active'] = $node->nodeData['name'];
		$parents = $node->getParentsNodes();
		if(sizeof($parents) > 1) { 
			$data['name2'] = $parents[sizeof($parents)-2]->nodeData['name'];
			$parentNode =  $parents[sizeof($parents)-2];
			$data['parentTree'] = $this->treeToArray($parentNode);
		} else { 
			$data['name2']=''; 
			$data['parentTree'] = null;
		}
		
		if(sizeof($parents) == 1){
			//print_r($data['currentSecondLevelMenu'] = $this->treeToArray($node));
			
			/*print_r($data['currentSecondLevelMenu'] = array(
				'name' => $node->nodeData['name'],
				'name_url' => $node->nodeData['name_url'],
				'link' => $node->nodeData['link'],
				'link_val' => $node->nodeData['link_val'],
				
				'tree' => $this->treeToArray($node)
			));*/
			
		} else if(sizeof($parents) == 2){	// tu już sam "else" powinien starczyć. bez drugiego "if" 
			//print_r($data['currentSecondLevelMenu'] = $this->treeToArray($node));
			
			/*print_r($data['currentSecondLevelMenu'] = array(
				'name' => $parents[0]->nodeData['name'],
				'name_url' => $parents[0]->nodeData['name_url'],
				'link' => $parents[0]->nodeData['link'],
				'link_val' => $parents[0]->nodeData['link_val'],
				
				'tree' => $this->treeToArray($parents[0])
			));*/
			
		} else {
			// gdy niżej w drzewie, to od jego pierwszego (albo drugiego?) przodka
			/*print_r($data['currentSecondLevelMenu'] = array(
				'name' => $parents[0]->nodeData['name'],
				'name_url' => $parents[0]->nodeData['name_url'],
				'link' => $parents[0]->nodeData['link'],
				'link_val' => $parents[0]->nodeData['link_val'],
				
				'tree' => $this->treeToArray($parents[0])
			));*/
		} 
		//print_r($parents);
		//$data['name2'] = $parents[sizeof($parents)-1]->nodeData['name'];
		$data['title'] = $node->nodeData['title'];
		$data['name_url'] = $node->nodeData['name_url'];
		$data['photo'] = $node->nodeData['photo']='' ? '' : $node->nodeData['photo'];
		
		$data['contact'] = $this->User_model->getContactData($this->userId);
		$data['logo'] = $this->User_model->getLogo($this->userId);
		$data['baner'] = $this->User_model->getBaner($this->userId);
		$data['slider'] = $this->User_model->getSlider($this->userId);
		$data['checkBaner'] = $this->User_model->checkBaner($this->userId, $mainId, $id);
		$data['checkSlider'] = $this->User_model->checkSlider($this->userId, $mainId, $id);
		
		$data['Google_Analytics'] = $this->User_model->getGACode($this->userId);
		
		$data['mainId'] = $this->mainId;
		$data['mainName'] = $this->mainName;
		
		if($node->nodeData['mini'] == 1) {
			$kids = $node->getNodeFirtLevelChilds2();
		} else $kids = NULL;
		
		$data['modules'] = array();
		$licznik = 0;
		$modulesArray = array();
		
		
		$translate = new stdClass();
		$img = new stdClass();
		$style = new stdClass();
		$translate_file = dirname(__FILE__).'/'.$base_template.'translate/translate'.(($this->lang_code == '')?(''):('_'.$this->lang_code)).'.php';
		if(file_exists($translate_file)) {
			include_once $translate_file;
		}
		$translate_img_file = dirname(__FILE__).'/'.$base_template.'translate/img'.(($this->lang_code == '')?(''):('_'.$this->lang_code)).'.php';
		if(file_exists($translate_img_file)){
			include_once $translate_img_file;
		}
		$translate->img = $img;
		$translate->style = $style;
		$data['translate'] = $translate;
		
		
		$data['news'] = $this->User_model->getNewsGlowny($this->userId);
		
		$data['szukaj'] = $this->szukaj;
		$data['znalezione'] = null;
		if($this->szukaj != ''){
			
			$data['znalezione'] = $this->User_model->szukaj($this->userId, $this->szukaj);
			/*foreach($data['znalezione']->result() as $row){
				echo $row->ID_nodes.'<br/>';
			}*/
		} else
		
		
		
		
		if($this->podstrona == 'Aktualnosci'){
			$data['content'] = '';
			/*if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/aktualnosci_wiecej.php')){
				$mod_view = '../../'.$this->folder.'/template/aktualnosci_wiecej';
			} else $mod_view = '../template/aktualnosci_wiecej';*/
			if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/aktualnosci_wiecej.php')){
				$mod_view = '../../'.$this->folder.'/template/aktualnosci_wiecej';
			} else {
				if(($user_template > 0) && ($user_template_folder != NULL)){
					$mod_view = '../template/'.$user_template_folder->global_templates_folder.'/modules/modules_source/aktualnosci_wiecej';
				} else {
					$mod_view = '../template/modules/modules_source/aktualnosci_wiecej';
				}
			}
			
			/*if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/aktualnosci_wiecej.php')){
				$mod_view = '../../'.$this->folder.'/template/aktualnosci_wiecej';
			} else {
				if($user_template == 1){
					$mod_view = '../template/base_template_1/modules/modules_source/aktualnosci_wiecej';
				} else if($user_template == 2){
					$mod_view = '../template/base_template_2/modules/modules_source/aktualnosci_wiecej';
				} else if($user_template == 3){
					$mod_view = '../template/base_template_3/modules/modules_source/aktualnosci_wiecej';
				} else {
					$mod_view = '../template/aktualnosci_wiecej';
				}
			}*/
			
			$content = $this->podstrona_dane;
			$newModule = array(
				'mod_view' => $mod_view,
				'mod_data' => array(
					'name' => '',
					'type' => '',
					'content' => $content
				)
			);
			array_push($modulesArray, $newModule);
		} else 	
			
		foreach($modules->result() as $module){
			$moduleId = $module->ID_modules;
			$name = $module->modules_name;
			$type = $module->modules_type;
			$nameShow = $module->modules_name_show;
			
			$content = null;
			if($type == "Tekst"){
				/*if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/tekst.php')){
					$mod_view = '../../'.$this->folder.'/template/tekst';
				} else $mod_view = '../template/tekst';*/
				
				if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/tekst.php')){
					$mod_view = '../../'.$this->folder.'/template/tekst';
				} else {
					if(($user_template > 0) && ($user_template_folder != NULL)){
						$mod_view = '../template/'.$user_template_folder->global_templates_folder.'/modules/modules_source/tekst';
					} else {
						$mod_view = '../template/modules/modules_source/tekst';
					}
				}
				/*
				if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/tekst.php')){
					$mod_view = '../../'.$this->folder.'/template/tekst';
				} else {
					if($user_template == 1){
						$mod_view = '../template/base_template_1/modules/modules_source/tekst';
					} else if($user_template == 2){
						$mod_view = '../template/base_template_2/modules/modules_source/tekst';
					} else if($user_template == 3){
						$mod_view = '../template/base_template_3/modules/modules_source/tekst';
					} else {
						$mod_view = '../template/tekst';
					}
				}
				*/
				$content = $this->User_model->getTextModule($moduleId); 
				if($content->num_rows()>0) $content = $content->row()->text_content; else $content = '';
				$newModule = array(
					'mod_view' => $mod_view,
					'mod_data' => array(
						'name' => $name,
						'name_show' => $nameShow,
						'type' => $type,
						'content' => $content
					)
				);
			} else if($type == "Galeria") {
				/*if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/galeria.php')){
					$mod_view = '../../'.$this->folder.'/template/galeria';
				} else $mod_view = '../template/galeria';*/
				
				if($module->modules_version == 0){
					if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/galeria.php')){
						$mod_view = '../../'.$this->folder.'/template/galeria';
					} else {
						if(($user_template > 0) && ($user_template_folder != NULL)){
							$mod_view = '../template/'.$user_template_folder->global_templates_folder.'/modules/modules_source/galeria';
						} else {
							$mod_view = '../template/modules/modules_source/galeria';
						}
					}
				} else if($module->modules_version == 1){
					if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/galeria2.php')){
						$mod_view = '../../'.$this->folder.'/template/galeria2';
					} else {
						if(($user_template > 0) && ($user_template_folder != NULL)){
							$mod_view = '../template/'.$user_template_folder->global_templates_folder.'/modules/modules_source/galeria2';
						} else {
							$mod_view = '../template/modules/modules_source/galeria2';
						}
					}
				}
				/*
				if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/galeria.php')){
					$mod_view = '../../'.$this->folder.'/template/galeria';
				} else {
					if($user_template == 1){
						$mod_view = '../template/base_template_1/modules/modules_source/galeria';
					} else if($user_template == 2){
						$mod_view = '../template/base_template_2/modules/modules_source/galeria';
					} else if($user_template == 3){
						$mod_view = '../template/base_template_3/modules/modules_source/galeria';
					} else {
						$mod_view = '../template/galeria';
					}
				}*/
				
				$content = $this->User_model->getPhotos($moduleId);
				//if($content->num_rows()>0) $content=$content; else $content=$content; 
				$newModule = array(
					'mod_view' => $mod_view,
					'mod_data' => array(
						'main_url' => $this->main_url,
						'name' => $name,
						'name_show' => $nameShow,
						'type' => $type,
						'content' => $content
					)
				);
			} else if($type == "Galeria wideo") {
				/*if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/wideo.php')){
					$mod_view = '../../'.$this->folder.'/template/wideo';
				} else $mod_view = '../template/wideo';*/
				
				if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/wideo.php')){
					$mod_view = '../../'.$this->folder.'/template/wideo';
				} else {
					if(($user_template > 0) && ($user_template_folder != NULL)){
						$mod_view = '../template/'.$user_template_folder->global_templates_folder.'/modules/modules_source/wideo';
					} else {
						$mod_view = '../template/modules/modules_source/wideo';
					}
				}			
				/*if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/wideo.php')){
					$mod_view = '../../'.$this->folder.'/template/wideo';
				} else {
					if($user_template == 1){
						$mod_view = '../template/base_template_1/modules/modules_source/wideo';
					} else if($user_template == 2){
						$mod_view = '../template/base_template_2/modules/modules_source/wideo';
					} else if($user_template == 3){
						$mod_view = '../template/base_template_3/modules/modules_source/wideo';
					} else {
						$mod_view = '../template/wideo';
					}
				}*/
				
				$content = $this->User_model->getVideos($moduleId);
				
				$size = $this->User_model->getvideosize($this->userId);
				if($size && $size->num_rows()>0){
					$row2 = $size->row();
					$rozmiar->x = $row2->videos_config_size_x;
					$rozmiar->y = $row2->videos_config_size_y;
				} else {
					$rozmiar->x = 250;
					$rozmiar->y = 200;
				}
				$data['rozmiar'] = $rozmiar;
				
				$newModule = array(
					'mod_view' => $mod_view,
					'mod_data' => array(
						'main_url' => $this->main_url,
						'name' => $name,
						'name_show' => $nameShow,
						'type' => $type,
						'content' => $content,
						'rozmiar' => $rozmiar
					)
				);
				
			} else if($type == "Polecane artykuły") {
				/*if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/polecane.php')){
					$mod_view = '../../'.$this->folder.'/template/polecane';
				} else $mod_view = '../template/polecane';*/
				
				if(file_exists((dirname(__FILE__).'/../../'.$this->folder.'/template/polecane.php'))){
					$mod_view = '../../'.$this->folder.'/template/polecane';
				} else {
					if(($user_template > 0) && ($user_template_folder != NULL)){
						$mod_view = '../template/'.$user_template_folder->global_templates_folder.'/modules/modules_source/polecane';
					} else {
						$mod_view = '../template/modules/modules_source/polecane';
					}
				}
				
				/*if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/polecane.php')){
					$mod_view = '../../'.$this->folder.'/template/polecane';
				} else {
					if($user_template == 1){
						$mod_view = '../template/base_template_1/modules/modules_source/polecane';
					} else if($user_template == 2){
						$mod_view = '../template/base_template_2/modules/modules_source/polecane';
					} else if($user_template == 3){
						$mod_view = '../template/base_template_3/modules/modules_source/polecane';
					} else {
						$mod_view = '../template/polecane';
					}
				}*/
				
				$polecane = $this->User_model->getRecommended($moduleId, $this->userId);
				
				$p_tab = NULL;
				if($polecane) foreach ($polecane as $p) {
					$n = new node($this->Tree_model, $p);
					$p_tab[] = array(
						'name'	=>	$n->nodeData['name'],
						'name_url'	=>	$n->nodeData['name_url'],
						'title'	=>	$n->nodeData['title'],
						'description'	=>	$n->nodeData['description'],
						'text'	=>	$n->nodeData['text'],
						'published'	=>	$n->nodeData['published'],
						'sitemap'	=>	$n->nodeData['sitemap'],
						'link'	=>	$n->nodeData['link'],
						'menu'	=>	$n->nodeData['menu'],
						'photo'	=>	$n->nodeData['photo'],
						'mini'	=>	$n->nodeData['mini'],
						'link_val'	=>	$n->nodeData['link_val']
					);
				}
				$newModule = array(
					'mod_view' => $mod_view,
					'mod_data' => array(
						'main_url' => $this->main_url,
						'name' => $name,
						'name_show' => $nameShow,
						'type' => $type,
						'content' => $p_tab
					)
				);
				
			} else if($type == "Aktualności"){
				
				/*if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/aktualnosci.php')){
					$mod_view = '../../'.$this->folder.'/template/aktualnosci';
				} else $mod_view = '../template/aktualnosci';*/
				
				if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/aktualnosci.php')){
					$mod_view = '../../'.$this->folder.'/template/aktualnosci';
				} else {
					if(($user_template > 0) && ($user_template_folder != NULL)){
						$mod_view = '../template/'.$user_template_folder->global_templates_folder.'/modules/modules_source/aktualnosci';
					} else {
						$mod_view = '../template/modules/modules_source/aktualnosci';
					}
				}
				
				/*if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/aktualnosci.php')){
					$mod_view = '../../'.$this->folder.'/template/aktualnosci';
				} else {
					if($user_template == 1){
						$mod_view = '../template/base_template_1/modules/modules_source/aktualnosci';
					} else if($user_template == 2){
						$mod_view = '../template/base_template_2/modules/modules_source/aktualnosci';
					} else if($user_template == 3){
						$mod_view = '../template/base_template_3/modules/modules_source/aktualnosci';
					} else {
						$mod_view = '../template/aktualnosci';
					}
				}*/
				
				$content = $this->User_model->getNews($moduleId);
				$newModule = array(
					'mod_view' => $mod_view,
					'mod_data' => array(
						'main_url' => $this->main_url,
						'name' => $name,
						'name_show' => $nameShow,
						'type' => $type,
						'content' => $content						
					)
				);
				
				//continue;
				
				
			} else if($type == "Formularz zgłoszeniowy"){
				/*if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/formularz_zgloszeniowy.php')){
					$mod_view = '../../'.$this->folder.'/template/formularz_zgloszeniowy';
				} else $mod_view = '../template/formularz_zgloszeniowy';*/
				
				if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/formularz_zgloszeniowy.php')){
					$mod_view = '../../'.$this->folder.'/template/formularz_zgloszeniowy';
				} else {
					if(($user_template > 0) && ($user_template_folder != NULL)){
						$mod_view = '../template/'.$user_template_folder->global_templates_folder.'/modules/modules_source/formularz_zgloszeniowy';
					} else {
						$mod_view = '../template/modules/modules_source/formularz_zgloszeniowy';
					}
				}
				
				/*if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/formularz_zgloszeniowy.php')){
					$mod_view = '../../'.$this->folder.'/template/formularz_zgloszeniowy';
				} else {
					if($user_template == 1){
						$mod_view = '../template/base_template_1/modules/modules_source/formularz_zgloszeniowy';
					} else if($user_template == 2){
						$mod_view = '../template/base_template_2/modules/modules_source/formularz_zgloszeniowy';
					} else if($user_template == 3){
						$mod_view = '../template/base_template_3/modules/modules_source/formularz_zgloszeniowy';
					} else {
						$mod_view = '../template/formularz_zgloszeniowy';
					}
				}*/
				
				$newModule = array(
					'mod_view' => $mod_view,
					'mod_data' => array(
						'type' => $type
					)
				);
			} else if($type == "Formularz kontaktowy"){
				/*if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/formularz_kontaktowy.php')){
					$mod_view = '../../'.$this->folder.'/template/formularz_kontaktowy';
				} else $mod_view = '../template/formularz_kontaktowy';*/
				
				if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/formularz_kontaktowy.php')){
					$mod_view = '../../'.$this->folder.'/template/formularz_kontaktowy';
				} else {
					if(($user_template > 0) && ($user_template_folder != NULL)){
						$mod_view = '../template/'.$user_template_folder->global_templates_folder.'/modules/modules_source/formularz_kontaktowy';
					} else {
						$mod_view = '../template/modules/modules_source/formularz_kontaktowy';
					}
				}
				
				/*if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/formularz_kontaktowy.php')){
					$mod_view = '../../'.$this->folder.'/template/formularz_zgloszeniowy';
				} else {
					if($user_template == 1){
						$mod_view = '../template/base_template_1/modules/modules_source/formularz_kontaktowy';
					} else if($user_template == 2){
						$mod_view = '../template/base_template_2/modules/modules_source/formularz_kontaktowy';
					} else if($user_template == 3){
						$mod_view = '../template/base_template_3/modules/modules_source/formularz_kontaktowy';
					} else {
						$mod_view = '../template/formularz_kontaktowy';
					}
				}*/
				
				$newModule = array(
					'mod_view' => $mod_view,
					'mod_data' => array(
						'main_url' => $this->main_url,
						'name' => $name,
						'name_show' => $nameShow,
						'type' => $type,
						'content' => $moduleId
					)
				);
			} else if($type == "FAQ"){
				/*if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/faq.php')){
					$mod_view = '../../'.$this->folder.'/template/faq';
				} else $mod_view = '../template/faq';*/
				
				if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/faq.php')){
					$mod_view = '../../'.$this->folder.'/template/faq';
				} else {
					if(($user_template > 0) && ($user_template_folder != NULL)){
						$mod_view = '../template/'.$user_template_folder->global_templates_folder.'/modules/modules_source/faq';
					} else {
						$mod_view = '../template/modules/modules_source/faq';
					}
				}
				
				/*if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/faq.php')){
					$mod_view = '../../'.$this->folder.'/template/faq';
				} else {
					if($user_template == 1){
						$mod_view = '../template/base_template_1/modules/modules_source/faq';
					} else if($user_template == 2){
						$mod_view = '../template/base_template_2/modules/modules_source/faq';
					} else if($user_template == 3){
						$mod_view = '../template/base_template_3/modules/modules_source/faq';
					} else {
						$mod_view = '../template/faq';
					}
				}*/
				
				$content = $this->User_model->getFaq($moduleId);
				$newModule = array(
					'mod_view' => $mod_view,
					'mod_data' => array(
						'main_url' => $this->main_url,
						'name' => $name,
						'name_show' => $nameShow,
						'type' => $type,
						'content' => $content
					)
				);
			} else if($type == "Pliki"){
				/*if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/pliki.php')){
					$mod_view = '../../'.$this->folder.'/template/pliki';
				} else $mod_view = '../template/pliki';*/
				
				if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/pliki.php')){
					$mod_view = '../../'.$this->folder.'/template/pliki';
				} else {
					if(($user_template > 0) && ($user_template_folder != NULL)){
						$mod_view = '../template/'.$user_template_folder->global_templates_folder.'/modules/modules_source/pliki';
					} else {
						$mod_view = '../template/modules/modules_source/pliki';
					}
				}
				
				/*if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/pliki.php')){
					$mod_view = '../../'.$this->folder.'/template/pliki';
				} else {
					if($user_template == 1){
						$mod_view = '../template/base_template_1/modules/modules_source/pliki';
					} else if($user_template == 2){
						$mod_view = '../template/base_template_2/modules/modules_source/pliki';
					} else if($user_template == 3){
						$mod_view = '../template/base_template_3/modules/modules_source/pliki';
					} else {
						$mod_view = '../template/pliki';
					}
				}*/
				
				$content = $this->User_model->getPliki($moduleId);
				$newModule = array(
					'mod_view' => $mod_view,
					'mod_data' => array(
						'main_url' => $this->main_url,
						'name' => $name,
						'name_show' => $nameShow,
						'type' => $type,
						'content' => $content
					)
				);
			} else if($type == "Mapa"){
				/*if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/mapa.php')){
					$mod_view = '../../'.$this->folder.'/template/mapa';
				} else $mod_view = '../template/mapa';*/
				
				if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/mapa.php')){
					$mod_view = '../../'.$this->folder.'/template/mapa';
				} else {
					if(($user_template > 0) && ($user_template_folder != NULL)){
						$mod_view = '../template/'.$user_template_folder->global_templates_folder.'/modules/modules_source/mapa';
					} else {
						$mod_view = '../template/modules/modules_source/mapa';
					}
				}
				
				/*if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/mapa.php')){
					$mod_view = '../../'.$this->folder.'/template/mapa';
				} else {
					if($user_template == 1){
						$mod_view = '../template/base_template_1/modules/modules_source/mapa';
					} else if($user_template == 2){
						$mod_view = '../template/base_template_2/modules/modules_source/mapa';
					} else if($user_template == 3){
						$mod_view = '../template/base_template_3/modules/modules_source/mapa';
					} else {
						$mod_view = '../template/mapa';
					}
				}*/
				
				$content = $this->User_model->getLocations($moduleId);
				$newModule = array(
					'mod_view' => $mod_view,
					'mod_data' => array(
						'main_url' => $this->main_url,
						'name' => $name,
						'name_show' => $nameShow,
						'type' => $type,
						'content' => $content
					)
				);
			} else if($type == "Baner"){
				/*if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/baner.php')){
					$mod_view = '../../'.$this->folder.'/template/baner';
				} else $mod_view = '../template/baner';*/
				
				if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/baner.php')){
					$mod_view = '../../'.$this->folder.'/template/baner';
				} else {
					if(($user_template > 0) && ($user_template_folder != NULL)){
						$mod_view = '../template/'.$user_template_folder->global_templates_folder.'/modules/modules_source/baner';
					} else {
						$mod_view = '../template/modules/modules_source/baner';
					}
				}
				
				/*if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/baner.php')){
					$mod_view = '../../'.$this->folder.'/template/baner';
				} else {
					if($user_template == 1){
						$mod_view = '../template/base_template_1/modules/modules_source/baner';
					} else if($user_template == 2){
						$mod_view = '../template/base_template_2/modules/modules_source/baner';
					} else if($user_template == 3){
						$mod_view = '../template/base_template_3/modules/modules_source/baner';
					} else {
						$mod_view = '../template/baner';
					}
				}	*/			
				
				$content = $this->User_model->getBanerPhotos($moduleId);
				$newModule = array(
					'mod_view' => $mod_view,
					'mod_data' => array(
						'main_url' => $this->main_url,
						'name' => $name,
						'name_show' => $nameShow,
						'type' => $type,
						'content' => $content
					)
				);
				
			} else if($type == "Slider"){
				
				
				if(file_exists(dirname(__FILE__).'/../../'.$this->folder.'/template/slider.php')){
					$mod_view = '../../'.$this->folder.'/template/slider';
				} else {
					if(($user_template > 0) && ($user_template_folder != NULL)){
						$mod_view = '../template/'.$user_template_folder->global_templates_folder.'/modules/modules_source/slider';
					} else {
						$mod_view = '../template/modules/modules_source/slider';
					}
				}
				
						
				
				$content = $this->User_model->getSliderPhotos($moduleId);
				$newModule = array(
					'mod_view' => $mod_view,
					'mod_data' => array(
						'main_url' => $this->main_url,
						'name' => $name,
						'name_show' => $nameShow,
						'type' => $type,
						'content' => $content
					)
				);
				
			}
			else {
				continue;
			}
			//$newModule = new module($name, $type, $content);
			array_push($modulesArray, $newModule);

		}
		$data['modules'] = $modulesArray;
		$data['kids'] = $kids;
		
		
		
		$data['recommended'] = '';
		
		$this->template->write_view('content', $template.'.php', $data);
				
		$onClose = '';
		$this->template->write_view('footer', $base_template.'footer');
		
		
		$this->template->render();
		
		
		if($this->User_model->check_cache($this->userId) == 1)	$this->output->cache(60);
		return;
		
		
		//$this->output->cache(10);
	}
	
	function cancel_newsletter(/*$userId,*/ $hash){
		//echo $userId.' '.$hash;
		//$this->userId = $userId;
		$this->adres = $this->User_model->getpagename($this->userId);
		
		$this->User_model->cancel_newsletter($this->userId, $hash);
		
		$this->messages->set_message('yellow', 'Zostałeś wypisany z newslettera!');
		redirect(prep_url($this->adres));
	}
	
	function add_to_newsletter(/*$userId*/){
		//$this->userId = $userId;
		$this->adres = $this->User_model->getpagename($this->userId);
		
		$this->load->helper('email');
		if($this->input->post('email', true) && valid_email($this->input->post('email', true))){
			
			$this->User_model->add_to_newsletter($this->userId, $this->input->post('email', true));
			
			$this->messages->set_message('yellow', 'Dziękujemy za zapisanie do newslettera!');
		} else {
			$this->messages->set_message('yellow', 'Wystąpił błąd');
		}
		redirect(prep_url($this->adres).'/'.$this->input->post('page'));
	}
	
	function send_contact(/*$userId*/){
		//$this->userId = $userId;
		
		$this->adres = $this->User_model->getpagename($this->userId);
		
		//$this->messages->set_message('green', 'blablabla '.$this->input->post('page'));
		//redirect(prep_url($this->adres).'/'.$this->input->post('page'), 'refresh');
		
		if($this->input->post('imie', TRUE) != '' && $this->input->post('nazwisko', TRUE) != '' 
			&& $this->input->post('mail', TRUE) != '' && $this->input->post('info', TRUE) != ''){
			
			$this->load->library('email');
			
			if($this->User_model->send_contact(
				$this->userId, 
				$this->input->post('imie', TRUE), 
				$this->input->post('nazwisko', TRUE), 
				$this->input->post('mail', TRUE), 
				$this->input->post('info', TRUE), 
				prep_url($this->adres).'/'.$this->input->post('page'), 
				$this->input->post('modId')) == TRUE){
				
				$this->messages->set_message('green', 'Dziękujemy za wysłanie wiadomości!');
			} else {
				$this->messages->set_message('green', 'Wystąpił błąd podczas wysyłania wiadomości');
			}
		} else {
			$this->messages->set_message('green', 'Nie wprowadzono wymaganych danych!');
		}
		redirect(prep_url($this->adres).'/'.$this->input->post('page'));
	}
	
	function send_contact_fk(/*$userId*/){
		//$this->userId = $userId;
		
		$this->adres = $this->User_model->getpagename($this->userId);
		
		$this->load->library('email');
		$this->load->helper('email');
		
		if(!valid_email($this->input->post('mail', true))){
			//echo $this->input->post('mail', true);
			//echo $this->input->post('mail');

			$this->messages->set_message('green', 'Nie wprowadzono wymaganych danych!aaaaa');
			redirect(prep_url($this->adres).'/'.$this->input->post('page'));
		}
		foreach($this->input->post('fk', true) as $val){
			
			if($val == ''){
				//echo $val.' / ';
				$this->messages->set_message('green', 'Nie wprowadzono wymaganych danych!bbbb');
				redirect(prep_url($this->adres).'/'.$this->input->post('page'));
			}
		}
		
		if($this->User_model->send_contact_fk($this->userId, $this->input->post('fk', true), $this->input->post('fk_name', true), 
			$this->input->post('mail', true), prep_url($this->adres).'/'.$this->input->post('page'), $this->input->post('modId'))){
			
			$this->messages->set_message('green', 'Dziękujemy za wysłanie wiadomości!');
		} else {
			$this->messages->set_message('green', 'Wystąpił błąd podczas wysyłania wiadomości');
		}
		
		
		redirect(prep_url($this->adres).'/'.$this->input->post('page'));
	}
	
	function aktualnosci(/*$user_id,*/ $lang_code, $node_name, $news_id, $news_name){
		//echo $user_id.$node_name.$news_id.$news_name;
		
		if($lang_code == 'pl') $this->lang_code = '';
		else $this->lang_code = $lang_code;
		$this->lang_nr = $this->User_model->getlang($this->userId, $lang_code);
		$this->load->model('../../../system/application/models/Tree_model');
		
		$news = $this->User_model->getSingleNews($this->userId, $node_name, $news_id, $news_name);
		if($news->num_rows() > 0) {
			$this->podstrona = 'Aktualnosci';
			$this->podstrona_dane = $news;
		}
		$this->page(/*$this->userId,*/ $lang_code, 0, $node_name);
		//echo $news->row()->news_text;
	}
	
	function aktualnosci_glowne(/*$user_id,*/ $lang_code, $node_name, $news_id, $news_name){
		//echo $user_id.$node_name.$news_id.$news_name;
		
		if($lang_code == 'pl') $this->lang_code = '';
		else $this->lang_code = $lang_code;
		$this->lang_nr = $this->User_model->getlang($this->userId, $lang_code);
		$this->load->model('../../../system/application/models/Tree_model');
		
		$news = $this->User_model->getSingleNewsGlowny($this->userId, $node_name, $news_id, $news_name, $this->lang_nr);
		if($news->num_rows() > 0) {
			$this->podstrona = 'Aktualnosci';
			$this->podstrona_dane = $news;
		}
		$this->page(/*$this->userId,*/ $lang_code, 0, $node_name);
		//echo $news->row()->news_text;
	}
	
	function abc(){
		echo 1111;
	}
}









/* Location: ./pages/application/controllers/main.php */