<?php

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

class Admin extends Controller {

	public $drzewo = '';
	public $lp = 0;
	public $polecaneTab = array();
	
	public $ckeditorBasePath = '';
	public $ckeditorCkfinder = '';
	
	public $lang_nr;
	
	public $blokada_stron;

	function Admin() {
		parent::Controller();
		
		//ini_set("memory_limit","50M");
		//set_time_limit(180);
		//ini_set('max_execution_time','180');
		//ini_set('max_input_time','300');
		
		$this->load->helper('url');
		
		$this->load->library('session');
		$this->load->library('messages');
		//$this->config->load('ustawienia');
		/*
		$config['hostname'] = $this->config->item('hostname');
		$config['username'] = $this->config->item('username');
		$config['password'] = $this->config->item('password');
		$config['database'] = $this->config->item('database');
		$config['dbdriver'] = $this->config->item('dbdriver');
		$config['dbprefix'] = $this->config->item('dbprefix');
		$config['pconnect'] = $this->config->item('pconnect');
		$config['db_debug'] = $this->config->item('db_debug');
		$config['cache_on'] = $this->config->item('cache_on');
		$config['cachedir'] = $this->config->item('cachedir');
		$config['char_set'] = $this->config->item('char_set');
		$config['dbcollat'] = $this->config->item('dbcollat');
		
		$this->load->database($config);
		*/
		$this->load->model('Admin_model');
		
		$this->load->helper('cookie');
		if($this->session->userdata('zalogowany') != TRUE){
			
			if(get_cookie('autologowanie')){ 
				$this->load->model('Admin_model');
				$this->Admin_model->auto_log_in_user(get_cookie('autologowanie'));
				//$this->session->set_userdata(array('blue' => 'Witaj ponownie!'));
				$this->messages->set_message('blue', 'Witaj ponownie!');
			} elseif($this->uri->segment(2)!='' && $this->uri->segment(2)!='index' && $this->uri->segment(2)!='loguj') {
				redirect(base_url(), 'refresh');
				//$this->index();
				//return;
			}
		} else {
			$this->load->model('Admin_model');
			$this->Admin_model->refresh_user_sess_vals($this->session->userdata('uzytkownik_id'));
		}
		$this->lang_nr = get_cookie('lang');	
		$this->load->helper('truncate');

		if($this->session->userdata('zalogowany') == true){
			$czas = $this->Admin_model->terminplatnosci($this->session->userdata('uzytkownik_id'));
			if($czas < 14){
				if($czas > 1)
					$this->messages->set_message('yellow', 'Uwaga! Za '.$czas.' dni upływa termin płatności. Prosimy o uiszczenie opłaty lub kontakt z administratorem.');
				if($czas == 1)
					$this->messages->set_message('yellow', 'Uwaga! Za '.$czas.' dzień upływa termin płatności. Prosimy o uiszczenie opłaty lub kontakt z administratorem.');
				if($czas < 1)
					$this->messages->set_message('yellow', 'Uwaga! Upłynął termin płatności. Prosimy o uiszczenie opłaty lub kontakt z administratorem.');
			}
		}
		
		$this->ckeditorBasePath = base_url().'asset/ckeditor/';
		$this->ckeditorCkfinder = 'asset/ckfinder';
		setcookie('folder', $this->Admin_model->get_user_folder($this->session->userdata('uzytkownik_id')), 0, '/');
		$adress = reduce_double_slashes(prep_url($this->Admin_model->get_user_pagename($this->session->userdata('uzytkownik_id'))).'/');
		$adress = explode("//", $adress);
		if(count($adress) > 1) setcookie('adres', $adress[1], 0, '/');
		
		$this->load->model('Admin_model');
		$this->blokada_stron = $this->Admin_model->sprawdz_blokade_stron($this->session->userdata('uzytkownik_id'));
	}
	
	private function getLocalTemplates($user){
		$this->load->helper('file');
		$this->load->model('Admin_model');
		/*$files = get_filenames(dirname(__FILE__).'/../../../pages/'.$this->Admin_model->get_user_folder($user).'/template/content');
		
		if($files) {
			foreach ($files as $key=>$file) {
				$filename = explode(".", $file);
				$newFilename = '';
				for($i = 0; $i < count($filename)-1; $i++){
					if($i > 0) $newFilename .= ".";
					$newFilename .= $filename[$i];
				} 
				$files[$key] = $newFilename;
			}	
		}*/
		$files = $this->Admin_model->getarticletemplates($this->session->userdata('uzytkownik_id'));
		
		return $files;
	}
	
	function loguj(){
		$this->load->model('Admin_model');
		
		$this->load->helper('cookie');
		
		delete_cookie('lang');
		
		$this->Admin_model->log_in_user(
			$this->input->post('login', TRUE),
			$this->input->post('haslo', TRUE),
			$this->input->post('autologowanie', TRUE)
		);
		$this->messages->set_message('blue', 'Witaj ponownie!');
		if($this->session->userdata('admin')==1) redirect(base_url().'administrator', 'refresh');	
		redirect(base_url(), 'refresh');	
	}
		
	function wyloguj(){
		$this->session->unset_userdata('uzytkownik');
		$this->session->unset_userdata('firma');
		$this->session->unset_userdata('uzytkownik_id');
		$this->session->unset_userdata('zalogowany');
		$this->session->unset_userdata('pagename');
		$this->session->unset_userdata('admin');
		$this->session->unset_userdata('tekst');
		$this->session->unset_userdata('ustawienia_strony');
		$this->session->unset_userdata('galeria');
		$this->session->unset_userdata('wideo');
		$this->session->unset_userdata('pa');
		$this->session->unset_userdata('news');
		$this->session->unset_userdata('fz');
		$this->session->unset_userdata('fk');
		$this->session->unset_userdata('faq');
		$this->session->unset_userdata('pliki');
		$this->session->unset_userdata('mapa');
		$this->session->unset_userdata('baner');
		$this->session->unset_userdata('sl');
		
		$this->session->unset_userdata('bg');
		$this->session->unset_userdata('ag');
		$this->session->unset_userdata('dk');
		$this->session->unset_userdata('l');
		$this->session->unset_userdata('nl');
		$this->session->unset_userdata('sg');
		
		$this->session->sess_destroy();
		
		$this->load->helper('cookie');
		delete_cookie("autologowanie");
		
		redirect(base_url(), 'refresh');
	}
	
	function displayTree($node) {
		if(!$node->getNodeChildsCount()) return;
		$nodes = $node->getNodeFirtLevelChilds();
		if($node->path=="root") $this->drzewo.= "<ul id='browser' class='filetree'> "; else 	$this->drzewo.= "<ul id='folder".$node->id."'>";

		foreach($nodes as $singleNode) {
			if($singleNode->getNodeChildsCount()) $isNextLevel="class='folder'"; else $isNextLevel="class='file'";
			$this->drzewo.= "<li><span id=".$singleNode->id." ".$isNextLevel."><a href='".base_url()."admin/wyswietl/".$singleNode->id."' >".$singleNode->nodeData['name']."</a></span>";
			if($singleNode->getNodeChildsCount()) $this->displayTree($singleNode);
			$this->drzewo.= "</li>";
		}
		$this->drzewo.= "</ul>";
	}
			
	private function getFolders($node, $pad = 0){
		if($pad == 0) $this->polecaneTab = array();
		if(!$node->getNodeChildsCount()) return NULL;
		$nodes = $node->getNodeFirtLevelChilds();
		foreach($nodes as $singleNode){
			if($singleNode->getNodeChildsCount()) {
				/*++$this->lp;
				if($pad == 0) $alt_row =  "class='alternate-row first_child'"; else $alt_row= "";
				$this->drzewo.="<tr ".$alt_row."><td>".$this->lp.".</td><td><span class='tableTreeTitle' style='padding-left: ".$pad."px;'>".$singleNode->nodeData['name']."</span></td>
				<td>
				
				</td>
				</tr>";
			*/	
				$singleNode->pad = $pad;
				$this->polecaneTab[] = $singleNode;
				$this->getFolders($singleNode, $pad + 20);
			}
		}
		return $this->polecaneTab;
	}
	
	private function getArticles($node, $pad = 0){
		if($pad == 0) $this->polecane = array();
		if(!$node->getNodeChildsCount()) return NULL;
		$nodes = $node->getNodeFirtLevelChilds();
		foreach ($nodes as $singleNode){
			if($singleNode->nodeData['published'] == 1){
				$singleNode->pad = $pad;
				$this->polecaneTab[] = $singleNode;
				$this->getArticles($singleNode, $pad + 20);
			}
		}
		return $this->polecaneTab;
	}
	
	function addnode() {
		//if($this->session->userdata('zalogowany')) {
			$this->load->library('validation');
			$rules['name']		= "required";
			$this->validation->set_rules($rules);
			
			if ($this->validation->run() == TRUE){
				$this->load->model('Admin_model');
				/*if($this->Admin_model->checkname_url(url_title($this->input->post('name', TRUE)))) {
					$this->messages->set_message('red', 'Dodawanie nowego elementu drzewa. Podana nazwa jest niedostępna');
					redirect(base_url().'admin/'.$this->input->post('redi'), 'refresh');
				}*/
				
				$urlnazwa = $this->Admin_model->checkname_url(url_title($this->input->post('name', TRUE)));
				
				$this->load->model('Tree_model');
			
				$newNode = new node($this->Tree_model, $this->input->post('id', TRUE));
		
				$dataNode->name = $this->input->post('name', TRUE);
				$dataNode->name_url = $urlnazwa;//url_title($this->input->post('name', TRUE));
				$dataNode->title = $this->input->post('title', TRUE); 
				$dataNode->description = $this->input->post('description', TRUE);
				$dataNode->text = '';//$this->input->post('text', TRUE);
				if($this->input->post('published', TRUE)==true) $dataNode->published=1; else $dataNode->published=0;
				if($this->input->post('sitemap', TRUE)==true) $dataNode->sitemap=1; else $dataNode->sitemap=0;
				if($this->input->post('link', TRUE)==true) $dataNode->link=1; else $dataNode->link=0;
				if($this->input->post('menu', TRUE)==true) $dataNode->menu=1; else $dataNode->menu=0;
				if($this->input->post('mini', TRUE)==true) $dataNode->mini=1; else $dataNode->mini=0;
				if($this->input->post('menu2', TRUE)==true) $dataNode->menu2=1; else $dataNode->menu2=0;
				$dataNode->template = $this->input->post('template_type');
				
				$dataNode->link_val = $this->input->post('link_val');
				
				$dataNode->photo = $_FILES['plik'];
				$this->load->model('Galeria_model');
				$size = $this->Galeria_model->getphotosize($this->session->userdata('uzytkownik_id'));
				if($size && $size->num_rows()>0){
					$row = $size->row();
					$dataNode->x = $row->gallery_config_size_x;
					$dataNode->y = $row->gallery_config_size_y;
				} else {
					$dataNode->x = 100;
					$dataNode->y = 80;
				}
				
				$newNode->addChild($dataNode);
				$newId = $newNode->getNewId();
				//redirect(base_url()/*.$this->session->userdata('lastPage')*/, 'refresh');
				$this->messages->set_message('green', 'Nowy element drzewa poprawnie dodany');
				redirect(base_url().'admin/wyswietl/'.$newId /*$this->input->post('redi', TRUE)*//*$this->session->userdata('lastPage')*/, 'refresh');
			} else {
				$this->messages->set_message('red', 'Dodawanie nowego elementu drzewa. Wypełnij wymagane pole "nazwa"');
				redirect(base_url().'admin/'.$this->input->post('redi'), 'refresh');
			}
								
		//} else redirect(base_url(), 'refresh');
	}
	
	function editnodetext(){
		//if($this->session->userdata('zalogowany')){
			$this->load->model('Tree_model');
			$newNode = new node($this->Tree_model);
			$dataNode->id = $this->input->post('id');
			$dataNode->text = $this->input->post('text');
			$newNode->updateNodeText($dataNode);
			$this->messages->set_message('green', 'Element drzewa poprawnie edytowany');
			redirect(base_url().'admin/'.$this->input->post('redi', TRUE)/*$this->session->userdata('lastPage')*/, 'refresh');
		//} else redirect(base_url(), 'refresh');
	}
	
	function editnode() {
		//if($this->session->userdata('zalogowany')) {
			$this->load->library('validation');
			$rules['name']		= "required";
			$this->validation->set_rules($rules);
			if ($this->validation->run() == TRUE){
				$this->load->model('Admin_model');
				/*if($this->Admin_model->checkname_url_update($this->input->post('id', TRUE), url_title($this->input->post('name', TRUE)))) {
					$this->messages->set_message('red', 'Edytowanie elementu drzewa. Podana nazwa jest niedostępna');
					redirect(base_url().'admin/'.$this->input->post('redi'), 'refresh');
				}*/
				
				$urlnazwa = $this->Admin_model->checkname_url_update($this->input->post('id', TRUE), url_title($this->input->post('name', TRUE)));
			
				$this->load->model('Tree_model');
		
				$newNode = new node($this->Tree_model);
				$dataNode->id = $this->input->post('id', TRUE);
				$dataNode->name = $this->input->post('name', TRUE);
				$dataNode->name_url = $urlnazwa;//url_title($this->input->post('name', TRUE));
				$dataNode->title = $this->input->post('title', TRUE); 
				$dataNode->description = $this->input->post('description', TRUE);
				//$dataNode->text = $this->input->post('text', TRUE);
				if($this->input->post('published', TRUE)==true) $dataNode->published=1; else $dataNode->published=0;
				if($this->input->post('sitemap', TRUE)==true) $dataNode->sitemap=1; else $dataNode->sitemap=0;
				if($this->input->post('link', TRUE)==true) $dataNode->link=1; else $dataNode->link=0;
				if($this->input->post('menu', TRUE)==true) $dataNode->menu=1; else $dataNode->menu=0;
				if($this->input->post('mini', TRUE)==true) $dataNode->mini=1; else $dataNode->mini=0;
				if($this->input->post('menu2', TRUE)==true) $dataNode->menu2=1; else $dataNode->menu2=0;
				$dataNode->template = $this->input->post('template_type');
				
				$dataNode->link_val = $this->input->post('link_val');
				
				if($this->input->post('photo', TRUE)==true){
					$dataNode->photo = $_FILES['plik'];
					$dataNode->delphoto = 0;
				} else {
					$dataNode->photo = NULL; 
					$dataNode->delphoto = 1;
				}
				
				$this->load->model('Galeria_model');
				$size = $this->Galeria_model->getphotosize($this->session->userdata('uzytkownik_id'));
				if($size && $size->num_rows()>0){
					$row = $size->row();
					$dataNode->x = $row->gallery_config_size_x;
					$dataNode->y = $row->gallery_config_size_y;
				} else {
					$dataNode->x = 100;
					$dataNode->y = 80;
				}
				
				//if($this->input->post('delphoto', TRUE)==true) $dataNode->delphoto=1; else $dataNode->delphoto=0;
				
				$newNode->updateNode($dataNode);
				$this->messages->set_message('green', 'Element drzewa poprawnie edytowany');
				redirect(base_url().'admin/'.$this->input->post('redi', TRUE)/*$this->session->userdata('lastPage')*/, 'refresh');
			} else {
				$this->messages->set_message('red', 'Edytowanie elementu drzewa. Wypełnij wymagane pole "nazwa"');
				redirect(base_url().'admin/'.$this->input->post('redi'), 'refresh');
			}
		//} else redirect(base_url(), 'refresh');
	}
	
	function deletenode() {
		//if($this->session->userdata('zalogowany')) {
			
			$this->load->model('Tree_model');
			
			$newNode = new node($this->Tree_model, $this->input->post('id', TRUE));

			$newNode->deleteNode();
			//redirect(base_url()/*.$this->session->userdata('lastPage')*/, 'refresh');
			$this->messages->set_message('green', 'Element drzewa poprawnie usunięty');
			if($this->input->post('redi') == 'wyswietl/'.$this->input->post('id')){
				redirect(base_url());
			}
			redirect(base_url().'admin/'/*.$this->input->post('redi', TRUE)/*$this->session->userdata('lastPage')*/, 'refresh');
		//} else redirect(base_url(), 'refresh');
	}
	
	function zapiszcss(){
		$folder = $this->Admin_model->get_user_folder($this->session->userdata('uzytkownik_id'));
		if(file_exists('./pages/'.$folder.'/css/style.css')){
			$this->load->helper('file');
			//$data['css'] = 
			chmod('./pages/'.$folder.'/css/style.css', 0666);
			write_file('./pages/'.$folder.'/css/style.css', $this->input->post('css'));
			$this->messages->set_message('green', 'Plik został zapisany.');
			
		} else {
			//data['css'] = '';
			$this->messages->set_message('red', 'Zapis się nie powiódł.');
		}
		
		redirect(base_url().'admin/wyswietl/'.$this->input->post('id'));
	}
	
	function wyswietl($id) {
		//if($this->session->userdata('zalogowany')) {
		
			$this->load->model('Admin_model');
			$this->load->model('Tree_model');
			
			/*$this->load->library('ckeditor');
	        $this->load->library('ckFinder');
			$this->ckeditor->basePath = base_url().'js/ckeditor/';
	        $this->ckeditor->config['toolbar'] = 'Full';
	        $this->ckeditor->config['language'] = 'pl';
	        /*$this->ckeditor->config['filebrowserUploadUrl'] = base_url().'drainase/upload_saluran_ckeditor';
	        $this->ckeditor->config['filebrowserImageUploadUrl'] = base_url().'drainase/upload_saluran_ckeditor';
	        //configure ckfinder with ckeditor config 
	        $this->ckfinder->SetupCKEditor($this->ckeditor, base_url().'js/ckfinder');*/
			
			
			
			$this->load->library('ckeditor');
	        $this->load->library('ckFinder');

	        $this->ckeditor->basePath = $this->ckeditorBasePath;
	        //$this->ckeditor->config['toolbar'] = 'Full';
	        //$this->ckeditor->config['language'] = 'pl';
	        $this->ckfinder->SetupCKEditor($this->ckeditor, $this->ckeditorCkfinder);
	                
	        
	        
			$this->session->set_userdata(array('lastPage' => 'admin/wyswietl/'.(string)$id));
		
			$newNode = new node($this->Tree_model, $id);
			
			if($newNode == NULL || $newNode->getUserId() != $this->session->userdata('uzytkownik_id')) redirect(base_url(), 'refresh');
			
			$data['parents'] = $newNode->getParentsNodes();
			$folder = $this->Admin_model->get_user_folder($this->session->userdata('uzytkownik_id'));
			if(file_exists('./pages/'.$folder.'/css/style.css')){
				$this->load->helper('file');
				$data['css'] = read_file('./pages/'.$folder.'/css/style.css');
				
			} else {
				$data['css'] = '';
			}
			
			$top_data['mainmenu'] = "Zarządzaj stroną";
			$top_data['submenu'] = "Zarządzaj stroną";
			$top_data['user_link'] = $this->Admin_model->getuserlink($this->session->userdata('uzytkownik_id'));
			$top_data['user_submenu'] = ''; 
			$top_data['multi'] = $this->Admin_model->checkmultilanguser($this->session->userdata('uzytkownik_id'));
			$top_data['langs'] = $this->Admin_model->getlangsuser($this->session->userdata('uzytkownik_id'));
			$this->load->view('localAdmin/top_view', $top_data); 
		
			$rootId = $this->Tree_model->getRootId($this->session->userdata("uzytkownik_id"));
			$this->drzewo = "<ul id='browser' class='filetree' style='float:left' >Zarządzaj podstronami:
<li><span id ='".$rootId."' class='rootId folder'><a href='".base_url()."' >root</a></span>";
			$root = new node($this->Tree_model, $rootId);
			$this->displayTree($root);
			$this->drzewo.="</li>
</ul>";
			$data['tree'] = $this->drzewo;
			
		
			$data['nodeData'] = $newNode->nodeData;
			
			$this->drzewo = '';
			$this->drzewo = "<ul id='browser' class='filetree' style='float:left' >
<li><span id ='".$newNode->id."' class='folder'><a href='".base_url()."admin/wyswietl/".$newNode->id."' >".$newNode->nodeData['name']."</a></span>";
			$this->displayTree($newNode);
			$this->drzewo.="</li>
</ul>";
			$data['small_tree'] = $this->drzewo;
			$this->drzewo ='';
		
			$this->load->model('Modul_model');
			$data['modules'] = $this->Modul_model->getModules($id, $this->session->userdata("uzytkownik_id"));
			
			
			$data['local_templates'] = $this->getLocalTemplates($this->session->userdata('uzytkownik_id'));
			$data['adres'] = $this->Admin_model->get_user_pagename($this->session->userdata('uzytkownik_id')); 
			
			$data['lang_code'] = $this->Admin_model->getlangcode($this->lang_nr);
			
			$this->load->view('localAdmin/content_top_view', $data);
			$this->load->view('localAdmin/admin_klient_wyswietl_view', $data);
			$this->load->view('localAdmin/content_bottom_view', $data);
			
			$dialog_data['local_templates'] = $this->getLocalTemplates($this->session->userdata('uzytkownik_id'));
			$dialog_data['default_article_template'] = $this->Admin_model->getarticletemplate($this->session->userdata('uzytkownik_id'));
			$this->load->view('localAdmin/dialog_view', $dialog_data);
			$this->load->view('localAdmin/bottom_view');
		//} else redirect(base_url(), 'refresh');
	}
	
	function moveup($id) {
		//if($this->session->userdata('zalogowany')) {
			
			$this->load->model('Tree_model');
			
			$node = new node($this->Tree_model, $id);
			$node->moveup();
			
			redirect(base_url().$this->session->userdata('lastPage'), 'refresh');
		//} else redirect(base_url(), 'refresh');
	}
	
	function movedown($id) {
		//if($this->session->userdata('zalogowany')) {
			
			$this->load->model('Tree_model');
			
			$node = new node($this->Tree_model, $id);
			$node->movedown();
		
			redirect(base_url().$this->session->userdata('lastPage'), 'refresh');
		//} else redirect(base_url(), 'refresh');
	}

	function addmodule() {
		//if($this->session->userdata('zalogowany')) {
			$this->load->library('validation');
			$rules['name']		= "required";
			$this->validation->set_rules($rules);
			if ($this->validation->run() == TRUE){
				$this->load->model('Modul_model');

				$newModuleId = $this->Modul_model->addmodule($this->input->post('name', TRUE), $this->input->post('module_type', TRUE), $this->input->post('id', TRUE), $this->session->userdata('uzytkownik_id'), $this->lang_nr, $this->input->post('name_show'));
			
				//redirect(base_url().'admin/wyswietl/'.$this->input->post("id", TRUE), 'refresh');
				$this->messages->set_message('green', 'Nowy moduł poprawnie dodany');
				redirect(base_url().'admin/module/'.$newModuleId, 'refresh');
			} else {
				$this->messages->set_message('red', 'Dodawanie nowego modułu. Wypełnij wymagane pole "nazwa"');
				redirect(base_url().'admin/'.$this->input->post('redi'), 'refresh');
			}
		//} else redirect(base_url(), 'refresh');
	}
	
	function setmodulesorder(){
		//if($this->session->userdata('zalogowany')) {
			
			$this->load->model('Modul_model');
			
			$this->Modul_model->setmodulesorder($this->input->post('module'));
		//} else redirect(base_url(), 'refresh');
	}
	
	function removemodule($id,$treeid,$type){
		//if($this->session->userdata('zalogowany')) {
			
			$this->load->model('Modul_model');
			
			$this->Modul_model->removemodule($id, $type);
			$this->messages->set_message('green', 'Moduł poprawnie usunięty');
			redirect(base_url().'admin/wyswietl/'.$treeid, 'refresh');
		//} else redirect(base_url(), 'refresh');
	}
	
	function module($id) {
		//if($this->session->userdata("zalogowany")){
		
			$this->load->model('Modul_model');
			
			$this->load->model('Tree_model');
			$this->load->model('Admin_model');
			
			
			$this->session->set_userdata(array('lastPage' => 'admin/module/'.$id));
			
			$thisNode = new node($this->Tree_model, $this->Modul_model->getParentOfModule($id));
			$data['parents'] = $thisNode->getParentsNodes();
					
			$top_data['mainmenu'] = "Zarządzaj stroną";
			$top_data['submenu'] = "Zarządzaj stroną";
			$top_data['user_link'] = $this->Admin_model->getuserlink($this->session->userdata('uzytkownik_id'));
			$top_data['user_submenu'] = '';
			$top_data['multi'] = $this->Admin_model->checkmultilanguser($this->session->userdata('uzytkownik_id'));
			$top_data['langs'] = $this->Admin_model->getlangsuser($this->session->userdata('uzytkownik_id'));
			$this->load->view('localAdmin/top_view', $top_data);
		
			$rootId = $this->Tree_model->getRootId($this->session->userdata("uzytkownik_id"));
			$this->drzewo = "<ul id='browser' class='filetree' style='float:left' >Zarządzaj podstronami:
<li><span id ='".$rootId."' class='rootId folder'><a href='".base_url()."' >root</a></span>";
			$root = new node($this->Tree_model, $rootId);
			$this->displayTree($root);
			$this->drzewo.="</li>
</ul>";
			$data['tree'] = $this->drzewo;
			
			$this->drzewo = '';
			
			
			$this->drzewo = "<ul id='browser' class='filetree' style='float:left' >
<li><span id ='".$thisNode->id."' class='folder'><a href='".base_url()."admin/wyswietl/".$thisNode->id."' >".$thisNode->nodeData['name']."</a></span>";
			$this->displayTree($thisNode);
			$this->drzewo.="</li>
</ul>";
			$data['small_tree'] = $this->drzewo;
			$this->drzewo ='';
			
			$row = $this->Modul_model->getmodule($id, $this->session->userdata('uzytkownik_id'))->row();
			$data['module'] = $row;
			//$row = $data['module']->row();
			
			$this->load->view('localAdmin/content_top_view', $data);
			
			$data['adres'] = $this->Admin_model->get_user_pagename($this->session->userdata('uzytkownik_id'));
			
			if($row->modules_type == 'Galeria') {
				$this->load->model('Galeria_model');
				$size = $this->Galeria_model->getphotosize($this->session->userdata('uzytkownik_id'));
				if($size && $size->num_rows()>0){
					$row2 = $size->row();
					$rozmiar->x = $row2->gallery_config_size_x;
					$rozmiar->y = $row2->gallery_config_size_y;
				} else {
					$rozmiar->x = 100;
					$rozmiar->y = 80;
				}
				$data['rozmiar'] = $rozmiar;
				$data['photos'] = $this->Modul_model->getphotos($id);
				$this->load->view('localAdmin/Galeria_module_view', $data);
			}
			elseif($row->modules_type == 'Tekst') {
				$this->load->model('Tekst_model');
				$data['text'] = $this->Tekst_model->getTextModule($id, $this->session->userdata('uzytkownik_id'));
				
				$this->load->library('ckeditor');
		        $this->load->library('ckFinder');
	
		        $this->ckeditor->basePath = $this->ckeditorBasePath;
		        $this->ckfinder->SetupCKEditor($this->ckeditor, $this->ckeditorCkfinder);
				
		        
				$this->load->view('localAdmin/Tekst_module_view', $data);
			}
			elseif($row->modules_type == 'Galeria wideo') {
				///
				$this->load->model('Wideo_model');
				$size = $this->Wideo_model->getvideosize($this->session->userdata('uzytkownik_id'));
				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;
				$data['movies'] = $this->Modul_model->getvideos($id);
				$this->load->view('localAdmin/Wideo_module_view', $data);
			}
			elseif($row->modules_type == 'Polecane artykuły') {
				$this->load->model('Polecane_model');
				$polecane = $this->Polecane_model->getrecommended($id);
				$data['latest'] = $polecane->polecane_latest;
				$polecane_array = array();
				if($polecane->polecane_val) {
					$p_expl = explode("/", $polecane->polecane_val);
					foreach($p_expl as $p){
						$polecane_array[] = $p;
					}
				}
				//$data['val'] = $polecane_array;
				if($polecane->polecane_latest == -1){
					$data['val_1'] = $polecane_array;
					$data['val_2'] = NULL;
				} else if($polecane->polecane_latest > 0){
					$data['val_2'] = $polecane_array;
					$data['val_1'] = NULL;
				} else {
					$data['val_1'] = NULL;
					$data['val_2'] = NULL;
				}
								
				$root = new node($this->Tree_model, $rootId);
				//$this->getFolders($root);
				//$this->polecaneTab = array();
				$data['artykuly'] = $this->getArticles($root);
				$data['kategorie'] = $this->getFolders($root);
				$this->load->view('localAdmin/Polecane_module_view', $data);
			}
			elseif($row->modules_type == 'Aktualności') {
				$this->load->model('News_model');
				$data['news'] = $this->News_model->getnews($id);
				
				
				$this->load->library('ckeditor');
		        $this->load->library('ckFinder');
	
		        $this->ckeditor->basePath = $this->ckeditorBasePath;
		        $this->ckfinder->SetupCKEditor($this->ckeditor, $this->ckeditorCkfinder);
	        
				
				$this->load->view('localAdmin/News_module_view', $data);
			}
			elseif($row->modules_type == 'Formularz zgłoszeniowy'){
				redirect(base_url().'admin/wyswietl/'.$row->modules_tree_id, 'refresh');
			}
			elseif($row->modules_type == 'Formularz kontaktowy'){

				$this->load->model('Modul_model');
				$data['mail'] = $this->Modul_model->getmailforcontactform($id);
				$this->load->view('localAdmin/Formularz_kontaktowy_module_view', $data);
				
				//redirect(base_url().'admin/wyswietl/'.$row->modules_tree_id, 'refresh');
			}
			elseif($row->modules_type == 'FAQ'){
				$this->load->model('Faq_model');
				
				$data['categories'] = $this->Faq_model->getfaqs($id);
				$this->load->view('localAdmin/FAQ_module_view', $data);
			}
			elseif($row->modules_type == 'Pliki'){
				$this->load->model('Pliki_model');
				$data['pliki'] = $this->Pliki_model->getfiles($id);
				$data['adres'] = $data['adres'] = $this->Admin_model->get_user_pagename($this->session->userdata('uzytkownik_id'));
				/*foreach($data['pliki']->result() as $a){
					echo $a->pliki_name;
				}*/
				$this->load->view('localAdmin/Pliki_module_view', $data);
			}
			elseif($row->modules_type == 'Mapa'){
				$this->load->model('Mapa_model');
				
				$this->load->view('localAdmin/Mapa_module_view', $data);
			}
			elseif($row->modules_type == 'Baner'){
				$this->load->model('Baner_model');
				
				$data['photos'] = $this->Modul_model->getbanerphotos($id);
				$this->load->view('localAdmin/Baner_module_view', $data);
			}
			elseif($row->modules_type == 'Slider'){
				$this->load->model('Slider_model');
				
				$data['photos'] = $this->Modul_model->getsliderphotos($id);
				$this->load->view('localAdmin/Slider_module_view', $data);
			}
			
			
			//...
			
			$this->load->view('localAdmin/content_bottom_view', $data);
			
			$dialog_data['local_templates'] = $this->getLocalTemplates($this->session->userdata('uzytkownik_id'));
			$dialog_data['default_article_template'] = $this->Admin_model->getarticletemplate($this->session->userdata('uzytkownik_id'));
			$this->load->view('localAdmin/dialog_view', $dialog_data);
			$this->load->view('localAdmin/bottom_view');
		//} else redirect(base_url(), 'refresh');
	}
	
	function addtextmodule() {
		//if($this->session->userdata("zalogowany")){
			
			$this->load->model('Tekst_model');
			
			$this->Tekst_model->addtextmodule($this->input->post('module_id', TRUE), $this->input->post('text', TRUE));
			
			$this->messages->set_message('green', 'Moduł poprawnie edytowany');
			redirect(base_url().'admin/module/'.$this->input->post('module_id', TRUE), 'refresh');
		//} else redirect(base_url(), 'refresh');
	}
	
	function edittextmodule() {
		//if($this->session->userdata("zalogowany")){

			$this->load->model('Tekst_model');

			$this->Tekst_model->edittextmodule($this->input->post('id', TRUE), $this->input->post('module_id', TRUE), $this->input->post('text', TRUE));
	
			$this->messages->set_message('green', 'Moduł poprawnie edytowany');
			redirect(base_url().'admin/module/'.$this->input->post('module_id', TRUE), 'refresh');
		//} else redirect(base_url(), 'refresh');
	}
	
	function editmodulename() {
		//if($this->session->userdata("zalogowany")){
			$this->load->model('Modul_model');
			/*if($this->input->post('mod_type') == 'Formularz kontaktowy'){
				$this->Modul_model->setmailforcontactform($this->input->post('module_id'), $this->input->post('mail'));
			}*/
			
			$this->load->library('validation');
			$rules['name']		= "required";
			$this->validation->set_rules($rules);
			if ($this->validation->run() == TRUE){
				
			
				$this->Modul_model->editmodulename($this->input->post('module_id', TRUE), $this->input->post('name', TRUE), $this->input->post('name_show'));
	
				$this->messages->set_message('green', 'Moduł poprawnie edytowany');
				redirect(base_url().'admin/wyswietl/'.$this->input->post('tree_id', TRUE), 'refresh');
			} else {
				$this->messages->set_message('red', 'Edycja modułu. Wypełnij wymagane pole "nazwa"');
				redirect(base_url().'admin/wyswietl/'.$this->input->post('tree_id', TRUE), 'refresh');
			}
		//} else redirect(base_url(), 'refresh');
	}
	
	function editfaqname(){
		$this->load->model('Faq_model');
		$this->load->library('validation');
		$rules['name'] = 'required';
		$this->validation->set_rules($rules);
		if ($this->validation->run() == TRUE){
			$this->Faq_model->editfaqname($this->input->post('faq_id', TRUE), $this->input->post('name', TRUE));
			$this->messages->set_message('green', 'FAQ poprawnie edytowany');
			redirect(base_url().'admin/module/'.$this->input->post('module_id', TRUE), 'refresh');
		} else {
			$this->messages->set_message('red', 'Edycja FAQ. Wypełnij wymagane pole "nazwa"');
			redirect(base_url().'admin/module/'.$this->input->post('module_id', TRUE), 'refresh');
		}
	}
	
	function editformmail() {
		$this->load->model('Modul_model');
		$this->Modul_model->setmailforcontactform($this->input->post('module_id'), $this->input->post('mail'));
		$this->messages->set_message('green', 'Adres e-mail poprawnie edytowany');
		redirect(base_url().'admin/module/'.$this->input->post('module_id', TRUE), 'refresh');
	}
	
	function editphotosize() {
		//if($this->session->userdata("zalogowany")){
			$this->load->library('validation');
			$rules['foto_x']		= "required";
			$rules['foto_y']		= "required";
			$this->validation->set_rules($rules);
			if ($this->validation->run() != TRUE){
				$this->messages->set_message('red', 'Edycja rozmiaru miniaturki. Wypełnij wymagane pola "Wysokość", "Szerokość"');
				redirect(base_url().'admin/konfiguracja_strony#ustawienia-foto-wideo', 'refresh');
			}
			$rules1['foto_x']		= "is_natural_no_zero";
			$rules1['foto_y']		= "is_natural_no_zero";
			$this->validation->set_rules($rules1);
			if ($this->validation->run() != TRUE){
				$this->messages->set_message('red', 'Edycja rozmiaru miniaturki. Wypełnij wymagane pola "Wysokość", "Szerokość" wartościami naturalnymi większymi od 0');
				redirect(base_url().'admin/konfiguracja_strony#ustawienia-foto-wideo', 'refresh');
			}
			$this->load->model('Galeria_model');
			
			$this->Galeria_model->editphotosize($this->session->userdata('uzytkownik_id'), $this->input->post('foto_x', TRUE), $this->input->post('foto_y', TRUE));
		
			//$this->messages->set_message('green', 'Domyślny rozmiar miniaturki poprawnie edytowany');

			//redirect(base_url().'admin/ustawienia/', 'refresh');

		//} else redirect(base_url(), 'refresh');
	}
	
	function editvideosize() {
		//if($this->session->userdata("zalogowany")){
			$this->load->library('validation');
			$rules['wideo_x']		= "required";
			$rules['wideo_y']		= "required";
			$this->validation->set_rules($rules);
			if ($this->validation->run() != TRUE){
				$this->messages->set_message('red', 'Edycja rozmiaru wideo. Wypełnij wymagane pola "Wysokość", "Szerokość"');
				redirect(base_url().'admin/konfiguracja_strony#ustawienia-foto-wideo', 'refresh');
			}
			$rules1['wideo_x']		= "is_natural_no_zero";
			$rules1['wideo_y']		= "is_natural_no_zero";
			$this->validation->set_rules($rules1);
			if ($this->validation->run() != TRUE){
				$this->messages->set_message('red', 'Edycja rozmiaru wideo. Wypełnij wymagane pola "Wysokość", "Szerokość" wartościami naturalnymi większymi od 0');
				redirect(base_url().'admin/konfiguracja_strony#ustawienia-foto-wideo', 'refresh');
			}
			$this->load->model('Wideo_model');
			
			$this->Wideo_model->editvideosize($this->session->userdata('uzytkownik_id'), $this->input->post('wideo_x', TRUE), $this->input->post('wideo_y', TRUE));
		
			//$this->messages->set_message('green', 'Rozmiar wideo poprawnie edytowany');

			//redirect(base_url().'admin/ustawienia/', 'refresh');
		
		//} else redirect(base_url(), 'refresh');
	}
	
	function editfotowideo(){
		if($this->input->post('galeria')==1){
			$this->editphotosize();
		}
		if($this->input->post('wideo')==1){
			$this->editvideosize();
		}
		$this->messages->set_message('green', 'Dane poprawnie edytowane');
		redirect(base_url().'admin/konfiguracja_strony', 'refresh');
	}
	
	function addphoto() {
		//if($this->session->userdata("zalogowany")){
			$this->load->library('validation');
			//$rules['header']		= "required";
			$rules['x']		= "required";
			//$rules['y']		= "required";
			$rules['foto_x']		= "required";
			//$rules['foto_y']		= "required";
			$this->validation->set_rules($rules);
			if ($this->validation->run() != TRUE){
				$this->messages->set_message('red', 'Dodawanie nowego zdjęcia. Wypełnij wymagane pole "Szerokość"');
				//$this->messages->set_message('red', 'Dodawanie nowego zdjęcia. Wypełnij wymagane pola "Nagłówek", "Wysokość", "Szerokość"');
				if($this->uri->segment(3) == 1){
					$file = $_FILES['plik'];
					$n = $file['name'];
					echo '{"name":"'.$n.'","message":"Wypełnij wymagane pole \"Szerokość\" "}';
					return;
				} else {
					redirect(base_url().'admin/module/'.$this->input->post('module_id', TRUE), 'refresh');
				}
			}
			$rules1['x']		= "is_natural_no_zero";
			//$rules1['y']		= "is_natural_no_zero";
			$rules1['foto_x']		= "is_natural_no_zero";
			//$rules1['foto_y']		= "is_natural_no_zero";
			$this->validation->set_rules($rules1);
			if ($this->validation->run() != TRUE){
				$this->messages->set_message('red', 'Dodawanie nowego zdjęcia. Wypełnij wymagane pole "Szerokość" wartościami naturalnymi większymi od 0');
				if($this->uri->segment(3) == 1){
					$file = $_FILES['plik'];
					$n = $file['name'];
					echo '{"name":"'.$n.'","message":"Wypełnij wymagane pole \"Szerokość\" wartościami naturalnymi większymi od 0"}';
					return;
				} else {
					redirect(base_url().'admin/module/'.$this->input->post('module_id', TRUE), 'refresh');
				}
			} else {
				$this->load->model('Galeria_model');
				$message = '';
				$ret = $this->Galeria_model->addphoto($this->input->post('module_id', TRUE), $this->input->post('x', TRUE), $this->input->post('y', TRUE), 
					$this->input->post('foto_x', TRUE), $this->input->post('foto_y', TRUE),
					$this->input->post('header', TRUE), $this->input->post('description', TRUE), $this->input->post('plik', TRUE));
				if($ret == false) {
					$message = 'Podaj plik w odpowiednim formacie (JPEG, GIF, PNG)';
					$this->messages->set_message('red', 'Dodawanie nowego zdjęcia. Podaj plik w odpowiednim formacie (JPEG, GIF, PNG)');
				} else {
					$message = 'Nowe zdjęcie poprawnie dodane';
					$this->messages->set_message('green', 'Nowe zdjęcie poprawnie dodane');
				}
				if($this->uri->segment(3) == 1){
					$file = $_FILES['plik'];
					$n = $file['name'];
					echo '{"name":"'.$n.'","message":"'.$message.'"}';	
					return;
				} else {
					redirect(base_url().'admin/module/'.$this->input->post('module_id', TRUE), 'refresh');
				}
			} 
		//} else redirect(base_url(), 'refresh');
	}
	
	function addbanerphoto(){
		/*$this->load->library('validation');
		$rules['foto_x']	=	"required";
		$rules['foto_y']	=	"required";
		$this->validation->set_rules($rules);
		if($this->validation->run() != TRUE){
			$this->messages->set_message('red', 'Dodawanie nowego zdjęcia baneru. Wypełnij wymagane pola "Wysokość", "Szerokość"');
			if($this->uri->segment(3) == 1){
				$file = $_FILES['plik'];
				$n = $file['name'];
				echo '{"name":"'.$n.'","message":"Wypełnij wymagane pola \"Wysokość\", \"Szerokość\" "}';
				return;
			} else {
				redirect(base_url().'admin/module/'.$this->input->post('module_id', TRUE), 'refresh');
			}
		}
		$rules1['foto_x']	=	"is_natural_no_zero";
		$rules1['foto_y']	=	"is_natural_no_zero";
		$this->validation->set_rules($rules1);
		if($this->validation->run() != TRUE){
			$this->messages->set_message('red', 'Dodawanie nowego zdjęcia baneru. Wypełnij wymagane pola "Wysokość", "Szerokość" wartościami naturalnymi większymi od 0');
			if($this->uri->segment(3) == 1){
				$file = $_FILES['plik'];
				$n = $file['name'];
				echo '{"name":"'.$n.'","message":"Wypełnij wymagane pola \"Wysokość\", \"Szerokość\" wartościami naturalnymi większymi od 0"}';
				return;
			} else {
				redirect(base_url().'admin/module/'.$this->input->post('module_id', TRUE), 'refresh');
			}
		} else {
			$this->load->model('Baner_model');
			$message = '';
			$ret = $this->Baner_model->addbanerphoto($this->input->post('module_id', TRUE), $this->input->post('foto_x', TRUE), $this->input->post('foto_y', TRUE),
				$this->input->post('header', TRUE), $this->input->post('plik', TRUE));
			if($ret == false) {
				$message = 'Podaj plik w odpowiednim formacie (JPEG, GIF, PNG)';
				$this->messages->set_message('red', 'Dodawanie nowego zdjęcia baneru. Podaj plik w odpowiednim formacie (JPEG, GIF, PNG)');
			} else {
				$message = 'Nowe zdjęcie baneru poprawnie dodane';
				$this->messages->set_message('green', 'Nowe zdjęcie baneru poprawnie dodane');
			}
			if($this->uri->segment(3) == 1){
				$file = $_FILES['plik'];
				$n = $file['name'];
				echo '{"name":"'.$n.'","message":"'.$message.'"}';
				return;
			} else {
				redirect(base_url().'admin/module/'.$this->input->post('module_id', TRUE), 'refresh');
			}
		}*/
		
		$this->load->model('Baner_model');
		$message = '';
		$img = '';
		$ret = $this->Baner_model->addbanerphoto($this->input->post('module_id', TRUE), $this->input->post('foto_x', TRUE), $this->input->post('foto_y', TRUE),
			$this->input->post('header', TRUE), $this->input->post('plik', TRUE), $this->input->post('change_size'));
		if($ret == false) {
			$img = '';
			$message = 'Podaj plik w odpowiednim formacie (JPEG, GIF, PNG)';
			$this->messages->set_message('red', 'Dodawanie nowego zdjęcia baneru. Podaj plik w odpowiednim formacie (JPEG, GIF, PNG)');
		} else {
			$img = $ret;
			$message = 'Nowe zdjęcie baneru poprawnie dodane';
			$this->messages->set_message('green', 'Nowe zdjęcie baneru poprawnie dodane');
		}
		if($this->uri->segment(3) == 1){
			$file = $_FILES['plik'];
			$n = $file['name'];
			//echo '{"name":"'.$n.'","message":"'.$message.'","img":"'.$img.'"}';
			echo $img.'';
			return;
		} else {
			redirect(base_url().'admin/module/'.$this->input->post('module_id', TRUE), 'refresh');
		}
	}
	
	function addsliderphoto(){
		
		$this->load->model('Slider_model');
		$message = '';
		$img = '';
		$ret = $this->Slider_model->addsliderphoto($this->input->post('module_id', TRUE), $this->input->post('foto_x', TRUE), $this->input->post('foto_y', TRUE),
			$this->input->post('header', TRUE), $this->input->post('plik', TRUE), $this->input->post('change_size'));
		if($ret == false) {
			$img = '';
			$message = 'Podaj plik w odpowiednim formacie (JPEG, GIF, PNG)';
			$this->messages->set_message('red', 'Dodawanie nowego zdjęcia slidera. Podaj plik w odpowiednim formacie (JPEG, GIF, PNG)');
		} else {
			$img = $ret;
			$message = 'Nowe zdjęcie slidera poprawnie dodane';
			$this->messages->set_message('green', 'Nowe zdjęcie slidera poprawnie dodane');
		}
		if($this->uri->segment(3) == 1){
			$file = $_FILES['plik'];
			$n = $file['name'];
			//echo '{"name":"'.$n.'","message":"'.$message.'","img":"'.$img.'"}';
			echo $img.'';
			return;
		} else {
			redirect(base_url().'admin/module/'.$this->input->post('module_id', TRUE), 'refresh');
		}
	}
	
	function addvideo(){
		if($this->uri->segment(3)){
			$this->load->model('Wideo_model');
			$this->Wideo_model->addvideo($this->input->post('module_id', TRUE), $this->input->post('videotype', TRUE), $this->input->post('header', TRUE),
				$this->input->post('description', TRUE), $this->input->post('uploaded_movie_name') /*$this->uri->segment(3)*/);
			//echo $this->input->post('uploaded_movie_name');
			return;
		} else {
		//if($this->session->userdata("zalogowany")){
			$this->load->library('validation');
			$rules['header']		= "required";
			$this->validation->set_rules($rules);
			if ($this->validation->run() != TRUE){
				$this->messages->set_message('red', 'Dodawanie nowego filmu. Wypełnij wymagane pole "Nagłówek"');
				redirect(base_url().'admin/module/'.$this->input->post('module_id', TRUE), 'refresh');
			} else {
				$this->load->model('Admin_model');
				if($this->input->post('videotype', TRUE) == 'file') {
					/*$rules1['x']		= "required";
					$rules1['y']		= "required";
					$this->validation->set_rules($rules1);
					if ($this->validation->run() != TRUE){
						$this->session->set_userdata(array('red' => 'Dodawanie nowego filmu. Wypełnij wymagane pola "Wysokość", "Szerokość"'));
						redirect(base_url().'admin/module/'.$this->input->post('module_id', TRUE), 'refresh');
					}*/
					$this->load->model('Wideo_model');
					$ret = $this->Wideo_model->addvideofile($this->input->post('module_id', TRUE), $this->input->post('videotype', TRUE), $this->input->post('header', TRUE), 
						$this->input->post('description', TRUE), $this->input->post('plik', TRUE));
					if($ret == false) {
						$this->messages->set_message('red', 'Dodawanie nowego filmu. Podaj plik w odpowiednim formacie ()');
					} else {
						$this->messages->set_message('green', 'Nowe wideo poprawnie dodane');
					}
					redirect(base_url().'admin/module/'.$this->input->post('module_id', TRUE), 'refresh');
					/*
					$config['upload_path'] = './video/';
					$config['allowed_types'] = 'avi|mpeg|mpg|mp4|png';
					$config['max_size']    = '1000000';
					
					$plik=$_FILES['plik'];
					$n=$plik['name'];
					$r=explode(".",$n);
					$nazwa_pliku=time().'.'.$r[count($r)-1];
					
					//$config['file_name'] = "123".$r[count($r)-1];//$nazwa_pliku;
					
					$this->load->library('upload', $config);
					
					$field_name = "plik";
					if($this->upload->do_upload($field_name)) echo (1); else echo (2);
					// For Debugging
					echo " Mime uploaded: ".$this->upload->file_type."<br>";
					foreach ($this->upload->allowed_types as $val)
					{
						echo "allowed: "; var_dump($this->upload->mimes_types(strtolower($val))); echo "<br>";
					}*/
				
				} else if($this->input->post('videotype', TRUE) == 'outsidelink') {
				
					$rules1['name']		= "required";
					$this->validation->set_rules($rules1);
					if ($this->validation->run() != TRUE){
						$this->messages->set_message('red', 'Dodawanie nowego filmu. Wypełnij wymagane pole "Zewnętrzny obiekt wideo"');
						redirect(base_url().'admin/module/'.$this->input->post('module_id', TRUE), 'refresh');
					} else {
						$this->load->model('Wideo_model');
						$this->Wideo_model->addvideolink($this->input->post('module_id', TRUE), $this->input->post('videotype', TRUE), $this->input->post('name'), 
							$this->input->post('header', TRUE), $this->input->post('description', TRUE) );
						
						$this->messages->set_message('green', 'Nowe wideo poprawnie dodane');
						redirect(base_url().'admin/module/'.$this->input->post('module_id', TRUE), 'refresh');
					}
					
				} else {
					$this->messages->set_message('red', 'Dodawanie nowego filmu. Wybierz typ filmu');
					redirect(base_url().'admin/module/'.$this->input->post('module_id', TRUE), 'refresh');
				}
			}
		//} else redirect(base_url(), 'refresh');
		}
	}
	
	function uploadfile(){
		//$plik=$_FILES['Filedata'];
		$plik=$_FILES['file'];
	
		if(/*in_array($plik['type'], array('video/mpeg', 'video/x-msvideo', 'application/octet-string'))*/ 1 == 1){		///   kombinować z typami plików
			$n=$plik['name'];
			$r=explode(".",$n);
			$nazwa_pliku=time().'.'.$r[count($r)-1];
			$folder = $this->db->get_where('users', array('ID_users' => $this->session->userdata('uzytkownik_id')))->row()->user_folder;
			if(@move_uploaded_file($plik['tmp_name'], 'pages/'.$folder.'/video/'.$nazwa_pliku)){
				
								
				//$order = $this->getMaxVideoOrder($moduleId) + 1;
				
				/*$data = array(
					'videos_module_id' => $moduleId,
					'videos_type' => $type,
					'videos_name' => $nazwa_pliku,
					'videos_header' => $header,
					'videos_description' => $description,
					'videos_order' => $order
				);*/
				//$this->db->set('videos_added', 'sysdate()', FALSE);
				//$this->db->insert('videos', $data);
				//echo ' '.$nazwa_pliku.' ';
			}
			//echo $nazwa_pliku;
			//echo '{"name":"'.$nazwa_pliku.'","type":"'.$plik['type'].'","size":"'.$plik['size'].'"}';
			echo $nazwa_pliku;
		} 
	}
	
	function setphotosorder(){
		//if($this->session->userdata("zalogowany")){
			
			$this->load->model('Galeria_model');
			
			$this->Galeria_model->setphotosorder($this->input->post('photo'));
		//} else redirect(base_url(), 'refresh');
	}
	
	function setvideosorder(){
		//if($this->session->userdata("zalogowany")){
			
			$this->load->model('Wideo_model');
			
			$this->Wideo_model->setvideosorder($this->input->post('video'));
		//} else redirect(base_url(), 'refresh');
	}
	
	function removephoto(){
		//if($this->session->userdata("zalogowany")){
			
			$this->load->model('Modul_model');
			
			$this->Modul_model->removephoto($this->input->post("id", TRUE), $this->input->post("name", TRUE));
			
			if($this->uri->segment(3) != 1)	$this->messages->set_message('green', 'Zdjęcie poprawnie usunięte');
			redirect(base_url().'admin/module/'.$this->input->post("module_id", TRUE), 'refresh');
		//} else redirect(base_url(), 'refresh');
	}
	
	function removevideo(){
		//if($this->session->userdata("zalogowany")){
			
			$this->load->model('Modul_model');
			
			$this->Modul_model->removevideo($this->input->post("id", TRUE), $this->input->post("name", TRUE), $this->input->post("type", TRUE));
			
			//$this->messages->set_message('green', 'Wideo poprawnie usunięte');
			redirect(base_url().'admin/module/'.$this->input->post("module_id", TRUE), 'refresh');
		//} else redirect(base_url(), 'refresh');
	}
	
	function eraseMessage($message){
		$this->session->unset_userdata($message);
		$this->load->helper('cookie');
		delete_cookie($message);
	}
	
	function ustawienia(){
		//if($this->session->userdata("zalogowany")){
			
			$this->load->model('Administrator_model');
			$this->load->model('Admin_model');
			
			$data['user'] = $this->Administrator_model->get_user($this->session->userdata('uzytkownik_id'))->row();
			
			
			$top_data['mainmenu'] = "Administracja";
			$top_data['submenu'] = "Ustawienia";
			$top_data['user_link'] = $this->Admin_model->getuserlink($this->session->userdata('uzytkownik_id'));
			$top_data['user_submenu'] = '';
			$top_data['multi'] = $this->Admin_model->checkmultilanguser($this->session->userdata('uzytkownik_id'));
			$top_data['langs'] = $this->Admin_model->getlangsuser($this->session->userdata('uzytkownik_id'));
			$this->load->view('localAdmin/top_view', $top_data);
			$this->load->view('localAdmin/content_top_view');
			$this->load->view('localAdmin/ustawienia_view', $data);
			$this->load->view('localAdmin/content_bottom_view');
			$this->load->view('localAdmin/bottom_view');
			
		//} else redirect(base_url(), 'refresh');
	}
	
	function edituser(){
		$this->load->library('validation');
		$rules['name']		= "required";
		$rules['mail']		= "required";
		$rules['pagename']	= "required";
		$this->validation->set_rules($rules);
			
		if ($this->validation->run() != TRUE){
			$this->messages->set_message('red', 'Edycja danych użytkownika. Wypełnij wymagane pola "Login", "Adres e-mail", "Adres strony internetowej"');
			redirect(base_url().'admin/ustawienia', 'refresh');		
		}
		$this->load->model('Admin_model');
		$this->Admin_model->edituser($this->session->userdata('uzytkownik_id'), $this->input->post('name', TRUE), $this->input->post('mail', TRUE), $this->input->post('pagename', TRUE)/*, $this->input->post('contact_mail', TRUE), $this->input->post('meta_title', TRUE), $this->input->post('meta_desc', TRUE)*/);
		
		$this->messages->set_message('green', 'Dane poprawnie edytowane');
		redirect(base_url().'admin/ustawienia', 'refresh');		
	}
	
	function editmetadane(){
		$this->load->model('Admin_model');
		$this->Admin_model->editmetadane($this->session->userdata('uzytkownik_id'), $this->input->post('meta_title', TRUE), $this->input->post('meta_desc', TRUE), $this->lang_nr);
		$this->messages->set_message('green', 'Dane poprawnie edytowane');
		redirect(base_url().'admin/konfiguracja_strony', 'refresh');
	}
	
	function zmiana_hasla(){
		//if($this->session->userdata("zalogowany")){
		
			$this->load->model('Admin_model');
			$top_data['mainmenu'] = "Administracja";
			$top_data['submenu'] = "Zmiana hasła";
			$top_data['user_link'] = $this->Admin_model->getuserlink($this->session->userdata('uzytkownik_id'));
			$top_data['user_submenu'] = '';
			$top_data['multi'] = $this->Admin_model->checkmultilanguser($this->session->userdata('uzytkownik_id'));
			$top_data['langs'] = $this->Admin_model->getlangsuser($this->session->userdata('uzytkownik_id'));
			$this->load->view('localAdmin/top_view', $top_data);
			$this->load->view('localAdmin/content_top_view');
			$this->load->view('localAdmin/zmiana_hasla_view');
			$this->load->view('localAdmin/content_bottom_view');
			$this->load->view('localAdmin/bottom_view');
		
		//} else redirect(base_url(), 'refresh');
	}
	
	function changepass(){
		//if($this->session->userdata("zalogowany")){
			$this->load->library('validation');
			$this->load->model('Admin_model');
			
			$rules['old_pass']		= "required";
			$rules['new_pass1']		= "required";
			$rules['new_pass2']		= "required";
			$this->validation->set_rules($rules);
				
			if ($this->validation->run() != TRUE){
				$this->messages->set_message('red', 'Zmiana hasła. Wypełnij wymagane pola "Stare hasło", "Nowe hasło", "Powtórz nowe hasło"');
				redirect(base_url().'admin/zmiana_hasla', 'refresh');	
			}
			
			if($this->Admin_model->checkpass($this->session->userdata('uzytkownik_id'), $this->input->post('old_pass')) != TRUE) {
				$this->messages->set_message('red', 'Zmiana hasła. Podaj prawidłowe "Stare hasło"');
				redirect(base_url().'admin/zmiana_hasla', 'refresh');
			}
			
			$rules1['new_pass1'] = "matches[new_pass2]";
			$this->validation->set_rules($rules1);
			if($this->validation->run() != TRUE){
				$this->messages->set_message('red', 'Zmiana hasła. Pola "Nowe hasło" i "Powtórz nowe hasło" powinny być takie same');
				redirect(base_url().'admin/zmiana_hasla', 'refresh');	
			}
		
			$this->Admin_model->changepass($this->session->userdata('uzytkownik_id'), $this->input->post('new_pass1'));
			
			$this->messages->set_message('green', 'Hasło poprawnie zmienione');
			redirect(base_url().'admin/zmiana_hasla', 'refresh');	

			
		//} else redirect(base_url(), 'refresh');
	}
	
	function modul_ustawienia($id){
		//if($this->session->userdata("zalogowany")){
		
			$this->load->model('Modul_model');
			$this->load->model('Tree_model');
			$this->load->model('Admin_model');
			
			$mod_type = $this->Modul_model->getmoduletype($id);
			
			$this->session->set_userdata(array('lastPage' => 'admin/module/'.$id));
			
			$thisNode = new node($this->Tree_model, $this->Modul_model->getParentOfModule($id));
			$data['parents'] = $thisNode->getParentsNodes();
					
			$top_data['mainmenu'] = "Zarządzaj stroną";
			$top_data['submenu'] = "Zarządzaj stroną";
			$top_data['user_link'] = $this->Admin_model->getuserlink($this->session->userdata('uzytkownik_id'));
			$top_data['user_submenu'] = '';
			$top_data['multi'] = $this->Admin_model->checkmultilanguser($this->session->userdata('uzytkownik_id'));
			$top_data['langs'] = $this->Admin_model->getlangsuser($this->session->userdata('uzytkownik_id'));
			$this->load->view('localAdmin/top_view', $top_data);
		
			$data['mod_type'] = $mod_type;
			if($mod_type == 'Formularz kontaktowy'){
				$data['mail'] = $this->Modul_model->getmailforcontactform($id);
			} else $data['mail'] = '';
			
			$rootId = $this->Tree_model->getRootId($this->session->userdata("uzytkownik_id"));
			$this->drzewo = "<ul id='browser' class='filetree' style='float:left' >Zarządzaj podstronami:
<li><span id ='".$rootId."' class='rootId folder'><a href='".base_url()."' >root</a></span>";
			$root = new node($this->Tree_model, $rootId);
			$this->displayTree($root);
			$this->drzewo.="</li>
</ul>";
			$data['tree'] = $this->drzewo;
			
			$this->drzewo = '';
			
			
			$this->drzewo = "<ul id='browser' class='filetree' style='float:left' >
<li><span id ='".$thisNode->id."' class='folder'><a href='".base_url()."admin/wyswietl/".$thisNode->id."' >".$thisNode->nodeData['name']."</a></span>";
			$this->displayTree($thisNode);
			$this->drzewo.="</li>
</ul>";
			$data['small_tree'] = $this->drzewo;
			$this->drzewo ='';
			
			$row = $this->Modul_model->getmodule($id, $this->session->userdata('uzytkownik_id'))->row();
			$data['module'] = $row;
			
			$this->load->view('localAdmin/content_top_view', $data);
			$this->load->view('localAdmin/modul_ustawienia_view', $data);
			$this->load->view('localAdmin/content_bottom_view', $data);

			$dialog_data['local_templates'] = $this->getLocalTemplates($this->session->userdata('uzytkownik_id'));
			$dialog_data['default_article_template'] = $this->Admin_model->getarticletemplate($this->session->userdata('uzytkownik_id'));
			$this->load->view('localAdmin/dialog_view', $dialog_data);
			$this->load->view('localAdmin/bottom_view');
		//} else redirect(base_url(), 'refresh');
	}
	
	function konfiguracja_strony(){
		//if($this->session->userdata("zalogowany")){
			$this->load->model('Admin_model');
			
			$top_data['mainmenu'] = "Administracja";
			$top_data['submenu'] = "Konfiguracja strony";
			$top_data['user_link'] = $this->Admin_model->getuserlink($this->session->userdata('uzytkownik_id'));
			$top_data['user_submenu'] = '';
			$top_data['multi'] = $this->Admin_model->checkmultilanguser($this->session->userdata('uzytkownik_id'));
			$top_data['langs'] = $this->Admin_model->getlangsuser($this->session->userdata('uzytkownik_id'));
			$this->load->view('localAdmin/top_view', $top_data);
			
			$this->load->model('Administrator_model');
			//$data['user'] = $this->Administrator_model->get_user($this->session->userdata('uzytkownik_id'))->row();
			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->model('Galeria_model');
			$photosize = $this->Galeria_model->getphotosize($this->session->userdata('uzytkownik_id'));
			if($photosize && $photosize->num_rows()>0){
				$row2 = $photosize->row();
				$photorozmiar->x = $row2->gallery_config_size_x;
				$photorozmiar->y = $row2->gallery_config_size_y;
			} else {
				$photorozmiar->x = 100;
				$photorozmiar->y = 80;
			}
			$data['photorozmiar'] = $photorozmiar;
			
			$this->load->model('Wideo_model');
			$videosize = $this->Wideo_model->getvideosize($this->session->userdata('uzytkownik_id'));
			if($videosize && $videosize->num_rows()>0){
				$row2 = $videosize->row();
				$videorozmiar->x = $row2->videos_config_size_x;
				$videorozmiar->y = $row2->videos_config_size_y;
			} else {
				$videorozmiar->x = 250;
				$videorozmiar->y = 200;
			}
			$data['videorozmiar'] = $videorozmiar;
			
			$data['templates'] = $this->Admin_model->getglobaltemplates();
			$data['template'] = $this->Admin_model->getpagetemplate($this->session->userdata('uzytkownik_id'));
			
			//$data['local_templates'] = $this->getLocalTemplates($this->session->userdata('uzytkownik_id'));
			$data['article_templates'] = $this->Admin_model->getarticletemplates($this->session->userdata('uzytkownik_id'));
			$data['default_article_template'] = $this->Admin_model->getarticletemplate($this->session->userdata('uzytkownik_id')); 
			
			/*$data['langs'] = $this->Admin_model->getlangs();
			$data['langs_user'] = $this->Admin_model->getlangsuser($this->session->userdata('uzytkownik_id'));
			*/
			
			$this->load->library('ckeditor');
	        $this->load->library('ckFinder');

	        $this->ckeditor->basePath = $this->ckeditorBasePath;
	        $this->ckfinder->SetupCKEditor($this->ckeditor, $this->ckeditorCkfinder);
			
	        
			$this->load->view('localAdmin/content_top_view');
			$this->load->view('localAdmin/konfiguracja_strony_view', $data);
			$this->load->view('localAdmin/content_bottom_view');
			
			$this->load->view('localAdmin/bottom_view');
		//} else redirect(base_url(), 'refresh');
	}
	
	function ustawienia_szablonow(){
		//if($this->session->userdata("zalogowany")){
			$this->load->model('Admin_model');
			
			$top_data['mainmenu'] = "Zarządzaj stroną";
			$top_data['submenu'] = "Ustawienia szablonów";
			$top_data['user_link'] = $this->Admin_model->getuserlink($this->session->userdata('uzytkownik_id'));
			$top_data['user_submenu'] = '';
			$top_data['multi'] = $this->Admin_model->checkmultilanguser($this->session->userdata('uzytkownik_id'));
			$top_data['langs'] = $this->Admin_model->getlangsuser($this->session->userdata('uzytkownik_id'));
			$this->load->view('localAdmin/top_view', $top_data);
			
			
			$data['adres'] = $this->Admin_model->get_user_pagename($this->session->userdata('uzytkownik_id'));
			$data['folder'] = $this->Admin_model->get_user_folder($this->session->userdata('uzytkownik_id'));
			
			$data['templates'] = $this->Admin_model->getglobaltemplates();
			$data['template'] = $this->Admin_model->getpagetemplate($this->session->userdata('uzytkownik_id'));
			
			//$data['local_templates'] = $this->getLocalTemplates($this->session->userdata('uzytkownik_id'));
			$data['article_templates'] = $this->Admin_model->getarticletemplates($this->session->userdata('uzytkownik_id'));
			$data['default_article_template'] = $this->Admin_model->getarticletemplate($this->session->userdata('uzytkownik_id')); 
			
			/*$data['langs'] = $this->Admin_model->getlangs();
			$data['langs_user'] = $this->Admin_model->getlangsuser($this->session->userdata('uzytkownik_id'));
			*/
			$this->load->view('localAdmin/content_top_view');
			$this->load->view('localAdmin/ustawienia_szablonow_view', $data);
			$this->load->view('localAdmin/content_bottom_view');
			
			$this->load->view('localAdmin/bottom_view');
		//} else redirect(base_url(), 'refresh');
	}
	
	function wersje_jezykowe(){
		$this->load->model('Admin_model');
		$top_data['mainmenu'] = "Administracja";
		$top_data['submenu'] = "Wersje językowe";
		$top_data['user_link'] = $this->Admin_model->getuserlink($this->session->userdata('uzytkownik_id'));
		$top_data['user_submenu'] = '';
		$top_data['multi'] = $this->Admin_model->checkmultilanguser($this->session->userdata('uzytkownik_id'));
		$top_data['langs'] = $this->Admin_model->getlangsuser($this->session->userdata('uzytkownik_id'));
		$this->load->view('localAdmin/top_view', $top_data);
		
		$data['langs'] = $this->Admin_model->getlangs();
		$data['langs_user'] = $this->Admin_model->getlangsuser2($this->session->userdata('uzytkownik_id'));
		
		$this->load->view('localAdmin/content_top_view');
		$this->load->view('localAdmin/wersje_jezykowe_view', $data);
		$this->load->view('localAdmin/content_bottom_view');
		
		$this->load->view('localAdmin/bottom_view');
	}
	
	/* niepotrzebne? */
	function setpagetemplate(){
		//if($this->session->userdata("zalogowany")){
			$this->load->model('Admin_model');
			$this->Admin_model->setpagetemplate($this->input->post('user_id'), $this->input->post('template_type'));
			$this->messages->set_message('green', 'Szablon strony poprawnie zmieniony');
			redirect(base_url().'admin/ustawienia_szablonow', 'refresh');
		//} else redirect(base_url(), 'refresh');
	}/****/
	
	function setdefaultarticletemplate(){
		//if($this->session->userdata("zalogowany")){
			$this->load->model('Admin_model');
			$this->Admin_model->setdefaultarticletemplate($this->input->post('user_id'), $this->input->post('article_template'));
			$this->messages->set_message('green', 'Domyślny szablon artykułów poprawnie ustawiony');
			redirect(base_url().'admin/ustawienia_szablonow', 'refresh');
		//} else redirect(base_url(), 'refresh');
	}
	
	function settemplates(){
		$this->load->model('Admin_model');
		$this->Admin_model->setpagetemplate($this->input->post('user_id'), $this->input->post('template_type'));
		$this->Admin_model->setdefaultarticletemplate($this->input->post('user_id'), $this->input->post('article_template'));
		redirect(base_url().'admin/konfiguracja_strony', 'refresh');
	}
	
	function setrecommended(){
		//if($this->session->userdata("zalogowany")){
			$this->load->model('Polecane_model');
			
			$polecane_val = '';
			if($this->input->post("polecane_type") == 1){
				$latest = -1;
				$lista = $this->input->post("polecane_art");
				if($lista) foreach ($lista as $art){
					$polecane_val .= $art.'/';
				}
			} else if($this->input->post("polecane_type") == 2){
				$latest = $this->input->post("pa_ile", TRUE); 
				$kategorie = $this->input->post("polecane_kat");
				if($kategorie) foreach ($kategorie as $kat){
					$polecane_val .= $kat.'/';
				}
			}
			
			$this->load->helper('string');
			$polecane_val = trim_slashes($polecane_val);
			
			$this->Polecane_model->setrecommended($this->input->post("module_id"), $latest, $polecane_val);
			$this->messages->set_message('green', 'Polecane artykuły zostały ustawione');
			redirect(base_url().'admin/module/'.$this->input->post("module_id"), 'refresh');
		//} else redirect(base_url(), 'refresh');
	}
	
	function addfaq(){
		//if($this->session->userdata("zalogowany")){
			
			$this->load->model('Faq_model');
			
			$this->Faq_model->addfaq($this->input->post('module_id', TRUE), $this->input->post('name', TRUE));
			
			$this->messages->set_message('green', 'Kategoria poprawnie dodana');
			redirect(base_url().'admin/module/'.$this->input->post('module_id', TRUE), 'refresh');
		//} else redirect(base_url(), 'refresh');
	}
	
	function faq($id){
		//if($this->session->userdata("zalogowany")){
			$this->load->model('Tree_model');
			$this->load->model('Faq_model');
			$this->load->model('Admin_model');
			
			$this->session->set_userdata(array('lastPage' => 'admin/faq/'.$id));
			$thisNode = new node($this->Tree_model, $this->Faq_model->getParentOfFaq($id));
			$data['parents'] = $thisNode->getParentsNodes();
			
			$top_data['mainmenu'] = "Zarządzaj stroną";
			$top_data['submenu'] = "Zarządzaj stroną";
			$top_data['user_link'] = $this->Admin_model->getuserlink($this->session->userdata('uzytkownik_id'));
			$top_data['user_submenu'] = '';
			$top_data['multi'] = $this->Admin_model->checkmultilanguser($this->session->userdata('uzytkownik_id'));
			$top_data['langs'] = $this->Admin_model->getlangsuser($this->session->userdata('uzytkownik_id'));
			$this->load->view('localAdmin/top_view', $top_data);
			
			$rootId = $this->Tree_model->getRootId($this->session->userdata("uzytkownik_id"));
			$this->drzewo = "<ul id='browser' class='filetree' style='float:left' >Zarządzaj podstronami:
<li><span id='".$rootId."' class='rootId folder'><a href='".base_url()."' >root</a></span>";
			$root = new node($this->Tree_model, $rootId);
			$this->displayTree($root);
			$this->drzewo.="</li>
</ul>";
			$data['tree'] = $this->drzewo;
			
			$this->drzewo = '';
			
			$this->drzewo = "<ul id='browser' class='filetree' style='float:left' >
<li><span id ='".$thisNode->id."' class='folder'><a href='".base_url()."admin/wyswietl/".$thisNode->id."' >".$thisNode->nodeData['name']."</a></span>";
			$this->displayTree($thisNode);
			$this->drzewo.="</li>
</ul>";
			$data['small_tree'] = $this->drzewo;
			$this->drzewo;
			$row = $this->Faq_model->getfaq($id/*, $this->session->userdata('uzytkownik_id')*/)->row();
			$data['FAQ'] = $row;
			
			$data['faqs'] = $this->Faq_model->getfaqsqa($id);
			
			$this->load->library('ckeditor');
	        $this->load->library('ckFinder');

	        $this->ckeditor->basePath = $this->ckeditorBasePath;
	        $this->ckfinder->SetupCKEditor($this->ckeditor, $this->ckeditorCkfinder);
			
			
			$this->load->view('localAdmin/content_top_view', $data);
			$this->load->view('localAdmin/FAQ_view', $data);
			$this->load->view('localAdmin/content_bottom_view', $data);
			
			
			$dialog_data['local_templates'] = $this->getLocalTemplates($this->session->userdata('uzytkownik_id'));
			$dialog_data['default_article_template'] = $this->Admin_model->getarticletemplate($this->session->userdata('uzytkownik_id'));
			$this->load->view('localAdmin/dialog_view', $dialog_data);
			$this->load->view('localAdmin/bottom_view');
		//} else redirect(base_url(), 'refresh');
	}
	
	function faqqa($id){
			$this->load->model('Tree_model');
			$this->load->model('Faq_model');
			$this->load->model('Admin_model');
			$faqId = $this->Faq_model->getfaqid($id);
			
			$this->session->set_userdata(array('lastPage' => 'admin/faqqa/'.$id));
			$thisNode = new node($this->Tree_model, $this->Faq_model->getParentOfFaq($faqId));
			$data['parents'] = $thisNode->getParentsNodes();
			
			$top_data['mainmenu'] = "Zarządzaj stroną";
			$top_data['submenu'] = "Zarządzaj stroną";
			$top_data['user_link'] = $this->Admin_model->getuserlink($this->session->userdata('uzytkownik_id'));
			$top_data['user_submenu'] = '';
			$top_data['multi'] = $this->Admin_model->checkmultilanguser($this->session->userdata('uzytkownik_id'));
			$top_data['langs'] = $this->Admin_model->getlangsuser($this->session->userdata('uzytkownik_id'));
			$this->load->view('localAdmin/top_view', $top_data);
			
			$rootId = $this->Tree_model->getRootId($this->session->userdata("uzytkownik_id"));
			$this->drzewo = "<ul id='browser' class='filetree' style='float:left' >Zarządzaj podstronami:
<li><span id='".$rootId."' class='rootId folder'><a href='".base_url()."' >root</a></span>";
			$root = new node($this->Tree_model, $rootId);
			$this->displayTree($root);
			$this->drzewo.="</li>
</ul>";
			$data['tree'] = $this->drzewo;
			
			$this->drzewo = '';
			
			$this->drzewo = "<ul id='browser' class='filetree' style='float:left' >
<li><span id ='".$thisNode->id."' class='folder'><a href='".base_url()."admin/wyswietl/".$thisNode->id."' >".$thisNode->nodeData['name']."</a></span>";
			$this->displayTree($thisNode);
			$this->drzewo.="</li>
</ul>";
			$data['small_tree'] = $this->drzewo;
			$this->drzewo;
			
			
			$row = $this->Faq_model->getfaq($faqId/*, $this->session->userdata('uzytkownik_id')*/)->row();
			$data['FAQ'] = $row;
			
			$data['faqqa'] = $this->Faq_model->getfaqqa($id)->row();
			
			$this->load->library('ckeditor');
	        $this->load->library('ckFinder');

	        $this->ckeditor->basePath = $this->ckeditorBasePath;
	        $this->ckfinder->SetupCKEditor($this->ckeditor, $this->ckeditorCkfinder);

	        
			$this->load->view('localAdmin/content_top_view', $data);
			$this->load->view('localAdmin/FAQ_qa_view', $data);
			$this->load->view('localAdmin/content_bottom_view', $data);
			
			
			$dialog_data['local_templates'] = $this->getLocalTemplates($this->session->userdata('uzytkownik_id'));
			$dialog_data['default_article_template'] = $this->Admin_model->getarticletemplate($this->session->userdata('uzytkownik_id'));
			$this->load->view('localAdmin/dialog_view', $dialog_data);
			$this->load->view('localAdmin/bottom_view');
	}
	
	function addfaqqa(){
		//if($this->session->userdata('zalogowany')){
			$this->load->model('Faq_model');
			
			$this->Faq_model->addfaqqa($this->input->post('faq_id'), $this->input->post('q'), $this->input->post('a'));
			
			$this->messages->set_message('green', 'Pytanie i odpowiedź poprawnie dodane');
			redirect(base_url().'admin/faq/'.$this->input->post('faq_id'));
		//} else redirect(base_url(), 'refresh');
	}
	
	function updatefaqqa(){
		$this->load->model('Faq_model');
		
		$this->Faq_model->updatefaqqa($this->input->post('faqqa_id'), $this->input->post('q'), $this->input->post('a'));
		
		$this->messages->set_message('green', 'Pytanie i odpowiedź poprawnie edytowane');
		redirect(base_url().'admin/faq/'.$this->Faq_model->getfaqid($this->input->post('faqqa_id')));
	}
	
	function removefaqqa($id,$faqa_id){
		//if($this->session->userdata('zalogowany')){
			$this->load->model('Modul_model');
			
			$this->Modul_model->removefaqqa($id);
			
			$this->messages->set_message('green', 'Pytanie i odpowiedź poprawnie usunięte');
			redirect(base_url().'admin/faq/'.$faqa_id);
		//} else redirect(base_url(), 'refresh');
	}
	
	function removefaq($id,$faq_id){
		//if($this->session->userdata('zalogowany')){
			$this->load->model('Modul_model');
			
			$this->Modul_model->removefaq($id);
			
			$this->messages->set_message('green', 'Pytanie i odpowiedź poprawnie usunięte');
			redirect(base_url().'admin/module/'.$faq_id);
		//} else redirect(base_url(), 'refresh');
	}
	
	function setfaqsorder(){
		//if($this->session->userdata("zalogowany")){
			
			$this->load->model('Faq_model');
			
			$this->Faq_model->setfaqsorder($this->input->post('faq'));
		//} else redirect(base_url(), 'refresh');
	}
	
	function setfaqsQAorder(){
		//if($this->session->userdata("zalogowany")){
			
			$this->load->model('Faq_model');
			
			$this->Faq_model->setfaqsQAorder($this->input->post('faqqa'));
		//} else redirect(base_url(), 'refresh');
	}
	
	function addnews(){
		$this->load->model('News_model');
		
		$urltitle = $this->News_model->checkname_url(url_title($this->input->post('title', TRUE)));
		$this->News_model->addnews($this->input->post('module_id'), $this->input->post('title'), $urltitle, $this->input->post('expiration_date'), $this->input->post('text_short'), $this->input->post('text'));
			//echo $this->input->post('expiration_date');	
		$this->messages->set_message('green', 'Nowa aktualność dodana');
		redirect(base_url().'admin/module/'.$this->input->post('module_id'));
	}
	
	function removenews($id, $module_id){
		$this->load->model('Modul_model');
		$this->Modul_model->removenews($id);
		$this->messages->set_message('green', 'Aktualność poprawnie usunięta');
		redirect(base_url().'admin/module/'.$module_id);
	}
	
	function news($id){
		$this->load->model('Modul_model');
		
		$this->load->model('Tree_model');
		$this->load->model('Admin_model');
		$this->load->model('News_model');
		
		
		$this->session->set_userdata(array('lastPage' => 'admin/news/'.$id));
		
		//$moduleId = $this->News_model->getmoduleid($id);
		$singlenews = $this->News_model->getsinglenews($id);
		$data['singlenews'] = $singlenews;
		$thisNode = new node($this->Tree_model, $this->Modul_model->getParentOfModule($singlenews->news_module_id));
		$data['parents'] = $thisNode->getParentsNodes();
				
		$top_data['mainmenu'] = "Zarządzaj stroną";
		$top_data['submenu'] = "Zarządzaj stroną";
		$top_data['user_link'] = $this->Admin_model->getuserlink($this->session->userdata('uzytkownik_id'));
		$top_data['user_submenu'] = '';
		$top_data['multi'] = $this->Admin_model->checkmultilanguser($this->session->userdata('uzytkownik_id'));
		$top_data['langs'] = $this->Admin_model->getlangsuser($this->session->userdata('uzytkownik_id'));
		$this->load->view('localAdmin/top_view', $top_data);
	
		$rootId = $this->Tree_model->getRootId($this->session->userdata("uzytkownik_id"));
		$this->drzewo = "<ul id='browser' class='filetree' style='float:left' >Zarządzaj podstronami:
<li><span id ='".$rootId."' class='rootId folder'><a href='".base_url()."' >root</a></span>";
		$root = new node($this->Tree_model, $rootId);
		$this->displayTree($root);
		$this->drzewo.="</li>
</ul>";
		$data['tree'] = $this->drzewo;
		
		$this->drzewo = '';
		
		
		$this->drzewo = "<ul id='browser' class='filetree' style='float:left' >
<li><span id ='".$thisNode->id."' class='folder'><a href='".base_url()."admin/wyswietl/".$thisNode->id."' >".$thisNode->nodeData['name']."</a></span>";
		$this->displayTree($thisNode);
		$this->drzewo.="</li>
</ul>";
		$data['small_tree'] = $this->drzewo;
		$this->drzewo ='';
		
		$row = $this->Modul_model->getmodule($singlenews->news_module_id, $this->session->userdata('uzytkownik_id'))->row();
		$data['module'] = $row;
		//$row = $data['module']->row();
		
		
		$this->load->library('ckeditor');
        $this->load->library('ckFinder');

        $this->ckeditor->basePath = $this->ckeditorBasePath;
        $this->ckfinder->SetupCKEditor($this->ckeditor, $this->ckeditorCkfinder);
		
				
		$this->load->view('localAdmin/content_top_view', $data);
		
		
		//$data['news'] = $this->News_model->getnews($id);
			
		$this->load->view('localAdmin/News_edit_view', $data);
		
		
		
		
		//...
		
		$this->load->view('localAdmin/content_bottom_view', $data);
		
		$dialog_data['local_templates'] = $this->getLocalTemplates($this->session->userdata('uzytkownik_id'));
		$dialog_data['default_article_template'] = $this->Admin_model->getarticletemplate($this->session->userdata('uzytkownik_id'));
		$this->load->view('localAdmin/dialog_view', $dialog_data);
		$this->load->view('localAdmin/bottom_view');
	}
	
	function editnews(){
		$this->load->model('News_model');
		$urltitle = $this->News_model->checkname_url_update($this->input->post('news_id'), url_title($this->input->post('title', TRUE)));
		
		$this->News_model->editnews($this->input->post('news_id'), $this->input->post('title'), $urltitle, $this->input->post('expiration_date'), $this->input->post('text_short'), $this->input->post('text'));
		$this->messages->set_message('green', 'Aktualność poprawnie edytowana');
		redirect(base_url().'admin/module/'.$this->input->post('module_id'));
	}
	
	function news_glowny(){
	
		$this->load->model('Admin_model');
		
				
		$top_data['mainmenu'] = "Zarządzanie kontenerami";
		$top_data['submenu'] = "Aktualności";
		$top_data['user_link'] = $this->Admin_model->getuserlink($this->session->userdata('uzytkownik_id'));
		$top_data['user_submenu'] = '';
		$top_data['multi'] = $this->Admin_model->checkmultilanguser($this->session->userdata('uzytkownik_id'));
		$top_data['langs'] = $this->Admin_model->getlangsuser($this->session->userdata('uzytkownik_id'));
		$this->load->view('localAdmin/top_view', $top_data);

		
				
		$this->load->model('News_glowny_model');

		$data['news'] = $this->News_glowny_model->getnewsglowny($this->session->userdata('uzytkownik_id'), ''.$this->lang_nr);
		
		$this->load->library('ckeditor');
        $this->load->library('ckFinder');

        $this->ckeditor->basePath = $this->ckeditorBasePath;
        $this->ckfinder->SetupCKEditor($this->ckeditor, $this->ckeditorCkfinder);
        
		
		$this->load->view('localAdmin/content_top_view');
		$this->load->view('localAdmin/news_glowny_view', $data);
		$this->load->view('localAdmin/content_bottom_view');
		
		$this->load->view('localAdmin/bottom_view');
	}
	
	function addnewsglowny(){
		$this->load->model('News_glowny_model');
		
		$urltitle = $this->News_glowny_model->checkname_url(url_title($this->input->post('title', TRUE)));
		$this->News_glowny_model->addnewsglowny($this->session->userdata('uzytkownik_id'), $this->input->post('title'), $urltitle, $this->input->post('expiration_date'), $this->input->post('text_short'), $this->input->post('text'), ''.$this->lang_nr.'');
			//echo $this->input->post('expiration_date');	
		$this->messages->set_message('green', 'Nowa aktualność dodana');
		redirect(base_url().'admin/news_glowny');
	}
	
	function news_glowny_edit($id){
		$this->load->model('Admin_model');
		
				
		$top_data['mainmenu'] = "Zarządzanie kontenerami";
		$top_data['submenu'] = "Aktualności";
		$top_data['user_link'] = $this->Admin_model->getuserlink($this->session->userdata('uzytkownik_id'));
		$top_data['user_submenu'] = '';
		$top_data['multi'] = $this->Admin_model->checkmultilanguser($this->session->userdata('uzytkownik_id'));
		$top_data['langs'] = $this->Admin_model->getlangsuser($this->session->userdata('uzytkownik_id'));
		$this->load->view('localAdmin/top_view', $top_data);
		
		$this->load->model('News_glowny_model');
		
		$singlenews = $this->News_glowny_model->getsinglenewsglowny($id);
		$data['singlenews'] = $singlenews;
		
		$this->load->library('ckeditor');
        $this->load->library('ckFinder');

        $this->ckeditor->basePath = $this->ckeditorBasePath;
        $this->ckfinder->SetupCKEditor($this->ckeditor, $this->ckeditorCkfinder);
		
		$this->load->view('localAdmin/content_top_view');
		$this->load->view('localAdmin/news_glowny_edit_view', $data);
		$this->load->view('localAdmin/content_bottom_view');
		
		$this->load->view('localAdmin/bottom_view');
	}
	
	function removenewsglowny($id){
		$this->load->model('News_glowny_model');
		$this->News_glowny_model->removenewsglowny($id);
		$this->messages->set_message('green', 'Aktualność poprawnie usunięta');
		redirect(base_url().'admin/news_glowny');
	}
	
	function editnewsglowny(){
		$this->load->model('News_glowny_model');
		$urltitle = $this->News_glowny_model->checkname_url_update($this->input->post('news_id'), url_title($this->input->post('title', TRUE)));
		
		$this->News_glowny_model->editnewsglowny($this->input->post('news_id'), $this->input->post('title'), $urltitle, $this->input->post('expiration_date'), $this->input->post('text_short'), $this->input->post('text'));
		$this->messages->set_message('green', 'Aktualność poprawnie edytowana');
		redirect(base_url().'admin/news_glowny');
	}
	
	function wyszukiwarka(){
		echo '...';
		
	}
	
	function addfile($moduleId){
		$file = $_FILES['file'];
		$this->load->model('Admin_model');
		$this->load->model('Pliki_model');
		$folder = $this->Admin_model->get_user_folder($this->session->userdata('uzytkownik_id'));
		
		$n=$file['name'];
		$r=explode(".",$n);
		$nazwa = '';
		for($i=0;$i < count($r)-1; $i++){
			$nazwa .= $r[$i];
			if($i != count($r)-2) $nazwa.= '.';
		}
		$nazwa = url_title($nazwa);
		$nazwa = $this->Pliki_model->checkname($moduleId, $nazwa, $r[count($r)-1], $folder);
		$nazwa_pliku = $nazwa.'.'.$r[count($r)-1];
		
		
		//time().'.'.$r[count($r)-1];
		
		if(@move_uploaded_file($file['tmp_name'], 'pages/'.$folder.'/uploads/'.$nazwa_pliku)){
			$this->Pliki_model->addfile($moduleId, $nazwa, $nazwa_pliku, $r[count($r)-1]);
			echo '{"name":"'.$nazwa_pliku.'","type":"'.$file['type'].'","size":"'.$file['size'].'"}';	
		} 
	}
	
	function removefile($id,$mod_id){
		$this->load->model('Admin_model');
		$this->load->model('Pliki_model');
		$folder = $this->Admin_model->get_user_folder($this->session->userdata('uzytkownik_id'));

		$this->load->model('Modul_model');
			
		$this->Modul_model->removefile($id, $folder);
		
		if($this->uri->segment(5) != 1){
			$this->messages->set_message('green', 'Plik poprawnie usunięty');
			redirect(base_url().'admin/module/'.$mod_id);
		}
	}
	
	function setfilesorder(){			
		$this->load->model('Pliki_model');
		$this->Pliki_model->setfilesorder($this->input->post('file'));
	}
	
	function savepoint(){
		$this->load->model('Mapa_model');
		$this->Mapa_model->savepoint($this->input->post('module_id'), $this->input->post('title'), $this->input->post('desc'), $this->input->post('lat'), $this->input->post('lng'));
		
		$this->messages->set_message('green', 'Pozycja na mapie zapisana');
		redirect(base_url().'admin/module/'.$this->input->post('module_id'));
	}
	
	function savepointjson(){
		$this->load->model('Mapa_model');
		$wynik = $this->Mapa_model->savepoint($this->input->post('module_id'), $this->input->post('title'), $this->input->post('desc'), $this->input->post('lat'), $this->input->post('lng'));
				
		//if($wynik>0) 
		echo json_encode(array("id" => $wynik, "tytul" => $this->input->post('title'), "opis" => $this->input->post('desc'), "lat" => $this->input->post('lat'), "lng" => $this->input->post('lng')));
		//else echo json_encode(array("id" => 0));
	}
	
	function getlocationsjson($mod_id){
		$this->load->model('Mapa_model');
		$locations = $this->Mapa_model->getlocations($mod_id);
		$points = array();
		
		if($locations && $locations->num_rows() > 0){
			foreach($locations->result() as $row){
				array_push($points, array('id' => $row->ID_mapa, 'tytul' => $row->mapa_tytul, 'opis' => $row->mapa_opis, 'lat' => $row->mapa_lat, 'lng' => $row->mapa_lng));
			}
		}
		echo json_encode(array("Locations"=>$points)); 
  		exit;
	}
	
	function removelocation($id, $mod_id){
		$this->load->model('Modul_model');
		$this->Modul_model->removelocation($id);
		
		$this->messages->set_message('Pozycja usunięta');
		redirect(base_url().'admin/module/'.$mod_id);
	}
	
	function setbanerphotosorder(){
		$this->load->model('Baner_model');
			
		$this->Baner_model->setbanerphotosorder($this->input->post('baner'));
	}
	
	function setsliderphotosorder(){
		$this->load->model('Slider_model');
			
		$this->Slider_model->setsliderphotosorder($this->input->post('slider'));
	}
	
	function removebanerphoto(){
		$this->load->model('Modul_model');
			
		$this->Modul_model->removebanerphoto($this->input->post("id", TRUE), $this->input->post("name", TRUE));
			
		if($this->uri->segment(3) != 1) $this->messages->set_message('green', 'Zdjęcie baneru poprawnie usunięte');
		redirect(base_url().'admin/module/'.$this->input->post("module_id", TRUE), 'refresh');
	}
	
	function removesliderphoto(){
		$this->load->model('Modul_model');
			
		$this->Modul_model->removesliderphoto($this->input->post("id", TRUE), $this->input->post("name", TRUE));
			
		if($this->uri->segment(3) != 1) $this->messages->set_message('green', 'Zdjęcie slidera poprawnie usunięte');
		redirect(base_url().'admin/module/'.$this->input->post("module_id", TRUE), 'refresh');
	}
	
	function getfotodata($id){	
		$this->load->model('Galeria_model');
		$photo = $this->Galeria_model->getphoto($id);
		
		if($photo) {
			$data['header'] = $photo->photos_header;
			$data['desc'] = $photo->photos_description;
		} else $data = NULL;
		
		$json = json_encode($data);
		echo $json;
	}
	
	function getvideodata($id){
		$this->load->model('Wideo_model');
		$video = $this->Wideo_model->getvideo($id);
		
		if($video) {
			$data['header'] = $video->videos_header;
			$data['desc'] = $video->videos_description;
		} else $data = NULL;
		
		$json = json_encode($data);
		echo $json;
	}
	
	function edytujfoto(){
		$this->load->model('Galeria_model');
		$this->Galeria_model->edytujfoto($this->input->post('foto_id'), $this->input->post('header'), $this->input->post('desc'));
			
		$this->messages->set_message('green', 'Zdjęcie poprawnie edytowane');
		redirect(base_url().'admin/module/'.$this->input->post('module_id'));
	}
	
	function edytujvideo(){
		$this->load->model('Wideo_model');
		$this->Wideo_model->edytujvideo($this->input->post('video_id'), $this->input->post('header'), $this->input->post('desc'));
			
		$this->messages->set_message('green', 'Opis filmu poprawnie edytowany');
		redirect(base_url().'admin/module/'.$this->input->post('module_id'));
	}
	
	function getbanerdata($id){
		$this->load->model('Baner_model');
		$baner = $this->Baner_model->getbaner($id);
		
		if($baner){
			$data['header'] = $baner->baner_header;
		} else $data = NULL;
		
		$json = json_encode($data);
		echo $json;
	}
	
	function getsliderdata($id){
		$this->load->model('Slider_model');
		$slider = $this->Slider_model->getslider($id);
		
		if($slider){
			$data['header'] = $slider->slider_header;
		} else $data = NULL;
		
		$json = json_encode($data);
		echo $json;
	}
	
	function edytujbaner(){
		$this->load->model('Baner_model');
		$this->Baner_model->edytujbaner($this->input->post('baner_id'), $this->input->post('header'));
		
		$this->messages->set_message('green', 'Zdjęcie baneru poprawnie edytowane');
		redirect(base_url().'admin/module/'.$this->input->post('module_id'));
	}
	
	function edytujslider(){
		$this->load->model('Slider_model');
		$this->Slider_model->edytujslider($this->input->post('slider_id'), $this->input->post('header'));
		
		$this->messages->set_message('green', 'Zdjęcie slidera poprawnie edytowane');
		redirect(base_url().'admin/module/'.$this->input->post('module_id'));
	}
	
	function addlang(){
		$this->load->model('Admin_model');
		$ret = $this->Admin_model->addlang($this->session->userdata('uzytkownik_id'), $this->input->post('lang'));		
		if($ret == false) $this->messages->set_message('red', 'Nie możesz wybrać tego języka ponownie');
		else $this->messages->set_message('green', 'Język poprawnie dodany');
		redirect(base_url().'admin/wersje_jezykowe');
	}
	
	function setlang(){
		$this->load->model('Admin_model');
		$this->Admin_model->setlang($this->input->post('lang_nr'));
		
		$this->messages->set_message('green', 'Język poprawnie zmieniony');
		redirect(base_url()/*.$this->input->post('last_page')*/);
	}
	
	function setlangsorder(){
		$this->load->model('Admin_model');
			
		$this->Admin_model->setlangsorder($this->input->post('lang'));
	}
	
	function dane_kontaktowe(){
		$this->load->model('Admin_model');
		$top_data['mainmenu'] = "Zarządzanie kontenerami";
		$top_data['submenu'] = "Dane kontaktowe";
		$top_data['user_link'] = $this->Admin_model->getuserlink($this->session->userdata('uzytkownik_id'));
		$top_data['user_submenu'] = '';
		$top_data['multi'] = $this->Admin_model->checkmultilanguser($this->session->userdata('uzytkownik_id'));
		$top_data['langs'] = $this->Admin_model->getlangsuser($this->session->userdata('uzytkownik_id'));
		$this->load->view('localAdmin/top_view', $top_data);
		
		$data['contact'] = $this->Admin_model->getcontactdata($this->session->userdata('uzytkownik_id'));
		
		$this->load->library('ckeditor');
        $this->load->library('ckFinder');

        $this->ckeditor->basePath = $this->ckeditorBasePath;
        $this->ckfinder->SetupCKEditor($this->ckeditor, $this->ckeditorCkfinder);

        
		$this->load->view('localAdmin/content_top_view');
		$this->load->view('localAdmin/dane_kontaktowe_view', $data);
		$this->load->view('localAdmin/content_bottom_view');
		
		$this->load->view('localAdmin/bottom_view');		
	}
	
	function setcontactdata(){
		$this->load->model('Admin_model');
		
		$this->Admin_model->setcontactdata($this->session->userdata('uzytkownik_id'), $this->input->post('nazwa'), $this->input->post('adres'), $this->input->post('telefon'), $this->input->post('mail'), $this->input->post('info'));
		$this->messages->set_message('green', 'Dane kontaktowe poprawnie zapisane');
		redirect(base_url().'admin/dane_kontaktowe');
	}
	
	function newsletter(){
		$this->load->model('Admin_model');
		$top_data['mainmenu'] = "Zarządzanie kontenerami";
		$top_data['submenu'] = "Newsletter";
		$top_data['user_link'] = $this->Admin_model->getuserlink($this->session->userdata('uzytkownik_id'));
		$top_data['user_submenu'] = '';
		$top_data['multi'] = $this->Admin_model->checkmultilanguser($this->session->userdata('uzytkownik_id'));
		$top_data['langs'] = $this->Admin_model->getlangsuser($this->session->userdata('uzytkownik_id'));
		$this->load->view('localAdmin/top_view', $top_data);
		
		
		$this->load->library('ckeditor');
        $this->load->library('ckFinder');

        $this->ckeditor->basePath = $this->ckeditorBasePath;
        $this->ckfinder->SetupCKEditor($this->ckeditor, $this->ckeditorCkfinder);
		
		$this->load->model('Newsletter_model');
		$data = array();
		$data['adresy'] = $this->Newsletter_model->get_adresy($this->session->userdata('uzytkownik_id'));
		$data['wiadomosci'] = $this->Newsletter_model->get_wiadomosci($this->session->userdata('uzytkownik_id'));
		// wczytać adresy newslettera, konfigurację newslettera
		
		$this->load->view('localAdmin/content_top_view');
		$this->load->view('localAdmin/newsletter_view', $data);
		$this->load->view('localAdmin/content_bottom_view');
		
		$this->load->view('localAdmin/bottom_view');
	}
	
	function addadres(){
		$this->load->model('Newsletter_model');
		$this->load->helper('email');
		if($this->input->post('email') && valid_email($this->input->post('email'))){
			$ret = $this->Newsletter_model->addadres($this->session->userdata('uzytkownik_id'), $this->input->post('email'));
			if($ret > 0){
				$this->messages->set_message('green', 'Adres e-mail poprawnie dodany');
			} else {
				$this->messages->set_message('red', 'Ten adres już znajduje się w bazie');
			}
			redirect(base_url().'admin/newsletter');
		} else {
			$this->messages->set_message('red', 'Podaj adres e-mail');
			redirect(base_url().'admin/newsletter');
		}
	}
	
	function removeadres($id){
		//sprawdzić czy ten id jest u tego użytkownika
		$this->load->model('Newsletter_model');

		$this->Newsletter_model->removeadres($this->session->userdata('uzytkownik_id'), $id);
	
		$this->messages->set_message('green', 'Adres został usunięty');
		redirect(base_url().'admin/newsletter');
	}
	
	function addwiadomosc(){
		$this->load->model('Newsletter_model');
		$this->load->helper('email');
		if($this->input->post('title')){
			
			$ret = $this->Newsletter_model->addwiadomosc($this->session->userdata('uzytkownik_id'), $this->input->post('title'), 
			$this->input->post('text'), $this->input->post('nadawca'), $this->input->post('nadawca_email'));
			
			if($ret > 0){
				$this->messages->set_message('green', 'Wiadomość została zapisana');
			} else {
				$this->messages->set_message('red', 'Wystąpił błąd');
			}
			
			redirect(base_url().'admin/newsletter');
		} else {
			$this->messages->set_message('red', 'Wypełnij wymagane pola');
			redirect(base_url().'admin/newsletter');
		}
	}
	
	function editwiadomosc(){
		$this->load->model('Newsletter_model');
		$this->load->helper('email');
		if($this->input->post('title')){
			$ret = $this->Newsletter_model->editwiadomosc($this->session->userdata('uzytkownik_id'), $this->input->post('id'),
			$this->input->post('title'), $this->input->post('text'), $this->input->post('nadawca'), $this->input->post('nadawca_email'));
			
			if($ret > 0){
				$this->messages->set_message('green', 'Wiadomość poprawnie zedytowana');
			} else {
				$this->messages->set_message('red', 'Nie dokonano zmian');
			}
			
			redirect(base_url().'admin/newsletter');
		} else {
			$this->messages->set_message('red', 'Wypełnij wymagane pola');
			redirect(base_url().'admin/newsletter');
		}
	}
	
	function removewiadomosc($id){
		$this->load->model('Newsletter_model');
		
		$this->Newsletter_model->removewiadomosc($this->session->userdata('uzytkownik_id'), $id);
		
		$this->messages->set_message('green', 'Wiadomość została usunięta.');
		redirect(base_url().'admin/newsletter');
	}
	
	function wyslijnewsletter($id){
		$this->load->model('Newsletter_model');
		$this->load->helper('email');
		$this->load->library('email');
		$this->load->helper('url');
		$this->load->helper('string');
		
		$this->Newsletter_model->wyslijnewsletter($this->session->userdata('uzytkownik_id'), $id);
		
		$this->messages->set_message('green', 'Newsletter został wysłany');
		redirect(base_url().'admin/newsletter');
	}
	
	function newsletter_wiadomosc($id){
		$this->load->model('Admin_model');
		$top_data['mainmenu'] = "Zarządzanie kontenerami";
		$top_data['submenu'] = "Newsletter";
		$top_data['user_link'] = $this->Admin_model->getuserlink($this->session->userdata('uzytkownik_id'));
		$top_data['user_submenu'] = '';
		$top_data['multi'] = $this->Admin_model->checkmultilanguser($this->session->userdata('uzytkownik_id'));
		$top_data['langs'] = $this->Admin_model->getlangsuser($this->session->userdata('uzytkownik_id'));
		$this->load->view('localAdmin/top_view', $top_data);
		
		
		$this->load->library('ckeditor');
        $this->load->library('ckFinder');

        $this->ckeditor->basePath = $this->ckeditorBasePath;
        $this->ckfinder->SetupCKEditor($this->ckeditor, $this->ckeditorCkfinder);
		
		$this->load->model('Newsletter_model');
		$data = array();
		
		$data['wiadomosci'] = $this->Newsletter_model->get_wiadomosc($this->session->userdata('uzytkownik_id'), $id);
		
		
		$this->load->view('localAdmin/content_top_view');
		$this->load->view('localAdmin/newsletter_wiadomosc_view', $data);
		$this->load->view('localAdmin/content_bottom_view');
		
		$this->load->view('localAdmin/bottom_view');
	}
	
	function logo_strony(){
		$this->load->model('Admin_model');
		$top_data['mainmenu'] = "Zarządzanie kontenerami";
		$top_data['submenu'] = "Logo strony";
		$top_data['user_link'] = $this->Admin_model->getuserlink($this->session->userdata('uzytkownik_id'));
		$top_data['user_submenu'] = '';
		$top_data['multi'] = $this->Admin_model->checkmultilanguser($this->session->userdata('uzytkownik_id'));
		$top_data['langs'] = $this->Admin_model->getlangsuser($this->session->userdata('uzytkownik_id'));
		$this->load->view('localAdmin/top_view', $top_data);

		$data['logo'] = $this->Admin_model->getlogo($this->session->userdata('uzytkownik_id'));
		$data['adres'] = $this->Admin_model->get_user_pagename($this->session->userdata('uzytkownik_id'));
		
		$this->load->view('localAdmin/content_top_view');
		$this->load->view('localAdmin/logo_strony_view', $data);
		$this->load->view('localAdmin/content_bottom_view');
		
		$this->load->view('localAdmin/bottom_view');
	}
	
	function setlogo(){
		$this->load->model('Admin_model');
				
		$message = '';
		$ret = $this->Admin_model->setlogo($this->input->post('plik', TRUE), $this->session->userdata('uzytkownik_id'));
		if($ret == false) {
			$message = 'Podaj plik w odpowiednim formacie (JPEG, GIF, PNG)';
			$this->messages->set_message('red', 'Ustawianie logo. Podaj plik w odpowiednim formacie (JPEG, GIF, PNG)');
		} else {
			$message = 'Logo poprawnie ustawione';
			$this->messages->set_message('green', 'Logo poprawnie ustawione');
		}
		if($this->uri->segment(3) == 1){
			$file = $_FILES['plik'];
			$n = $file['name'];
			echo '{"name":"'.$n.'","message":"'.$message.'"}';
			return;
		} else {
			redirect(base_url().'admin/logo_strony', 'refresh');
		}
				
	}
	
	function deactivatelang(){
		$this->load->model('Admin_model');
		$this->Admin_model->deactivatelang($this->input->post('ID_langs_user'));
		$this->messages->set_message('green', 'Język został wyłączony');
		redirect(base_url().'admin/wersje_jezykowe', 'refresh');
	} 
	
	function activatelang(){
		$this->load->model('Admin_model');
		$this->Admin_model->activatelang($this->input->post('ID_langs_user'));
		$this->messages->set_message('green', 'Język został włączony');
		redirect(base_url().'admin/wersje_jezykowe', 'refresh');
	}
	
	function togglehelpcookie(){
		$help_status = get_cookie('help');
		if($help_status == 1){
			$cookie = array(
				'name'   => 'help',
				'value'  => 0,
				'expire' => '865000'
			);

			set_cookie($cookie);
		} else {
			$cookie = array(
				'name'   => 'help',
				'value'  => 1,
				'expire' => '865000'
			);

			set_cookie($cookie);			
		}
	}
	
	function cropbaner(){
		$this->load->model('Baner_model');
		$this->Baner_model->cropbaner($this->input->post('foto'), $this->input->post('x'), $this->input->post('y'),
			$this->input->post('x2'), $this->input->post('y2'), $this->input->post('h'), $this->input->post('w'));
		/*$n = explode("/", $this->input->post('foto'));
		$nazwa = $n[count($n)-1];
		echo $nazwa;*/
		echo '1'; 
		
	}
	
	function cropslider(){
		$this->load->model('Slider_model');
		$this->Slider_model->cropslider($this->input->post('foto'), $this->input->post('x'), $this->input->post('y'),
			$this->input->post('x2'), $this->input->post('y2'), $this->input->post('h'), $this->input->post('w'));
		/*$n = explode("/", $this->input->post('foto'));
		$nazwa = $n[count($n)-1];
		echo $nazwa;*/
		echo '1'; 
		
	}
	
	function baner(){
		$this->load->model('Admin_model');
		$top_data['mainmenu'] = "Zarządzanie kontenerami";
		$top_data['submenu'] = "Baner";
		$top_data['user_link'] = $this->Admin_model->getuserlink($this->session->userdata('uzytkownik_id'));
		$top_data['user_submenu'] = '';
		$top_data['multi'] = $this->Admin_model->checkmultilanguser($this->session->userdata('uzytkownik_id'));
		$top_data['langs'] = $this->Admin_model->getlangsuser($this->session->userdata('uzytkownik_id'));
		$this->load->view('localAdmin/top_view', $top_data);
		
		$this->load->model('Baner_glowny_model');
		$data['adres'] = $this->Admin_model->get_user_pagename($this->session->userdata('uzytkownik_id'));
		$data['photos'] = $this->Baner_glowny_model->getbanerglownyphotos($this->session->userdata('uzytkownik_id'));
		$data['allpages'] = $this->Baner_glowny_model->checkallpages($this->session->userdata('uzytkownik_id'));
		
		$this->load->view('localAdmin/content_top_view');
		$this->load->view('localAdmin/baner_glowny_view', $data);
		$this->load->view('localAdmin/content_bottom_view');
		
		$this->load->view('localAdmin/bottom_view');
	}
	
	function banerglownyustawienia(){
		$this->load->model('Baner_glowny_model');
		$this->Baner_glowny_model->banerglownyustawienia($this->session->userdata('uzytkownik_id'), $this->input->post('checkbaner'));
		redirect(base_url().'admin/baner');
	}
	
	function addbanerglownyphoto(){
		$this->load->model('Baner_glowny_model');
		$message = '';
		$img = '';
		$ret = $this->Baner_glowny_model->addbanerglownyphoto($this->input->post('user_id', TRUE), $this->input->post('foto_x', TRUE), $this->input->post('foto_y', TRUE),
			$this->input->post('header', TRUE), $this->input->post('plik', TRUE), $this->input->post('change_size'), $this->input->post('link'));
		if($ret == false) {
			$img = '';
			$message = 'Podaj plik w odpowiednim formacie (JPEG, GIF, PNG)';
			$this->messages->set_message('red', 'Dodawanie nowego zdjęcia baneru. Podaj plik w odpowiednim formacie (JPEG, GIF, PNG)');
		} else {
			$img = $ret;
			$message = 'Nowe zdjęcie baneru poprawnie dodane';
			$this->messages->set_message('green', 'Nowe zdjęcie baneru poprawnie dodane');
		}
		if($this->uri->segment(3) == 1){
			$file = $_FILES['plik'];
			$n = $file['name'];
			//echo '{"name":"'.$n.'","message":"'.$message.'","img":"'.$img.'"}';
			echo $img.'';
			return;
		} else {
			redirect(base_url().'admin/baner', 'refresh');
		}
	}
	
	function getbanerglownydata($id){
		$this->load->model('Baner_glowny_model');
		$baner = $this->Baner_glowny_model->getbanerglowny($id);
		
		if($baner){
			$data['header'] = $baner->baner_glowny_header;
			$data['link'] = $baner->baner_glowny_link;
		} else $data = NULL;
		
		$json = json_encode($data);
		echo $json;
	}
	
	function edytujbanerglowny(){
		$this->load->model('Baner_glowny_model');
		$this->Baner_glowny_model->edytujbanerglowny($this->input->post('baner_id'), $this->input->post('header'), $this->input->post('link'));
		
		$this->messages->set_message('green', 'Zdjęcie baneru poprawnie edytowane');
		redirect(base_url().'admin/baner');
	}
	
	function cropbanerglowny(){
		$this->load->model('Baner_glowny_model');
		$this->Baner_glowny_model->cropbaner($this->input->post('foto'), $this->input->post('x'), $this->input->post('y'),
			$this->input->post('x2'), $this->input->post('y2'), $this->input->post('h'), $this->input->post('w'));
		echo '1';		
	}
	
	function removebanerglownyphoto(){
		//$this->load->model('Modul_model');
		$this->load->model('Baner_glowny_model');
			
		$this->Baner_glowny_model->removebanerglownyphoto($this->input->post("id", TRUE), $this->input->post("name", TRUE));
			
		if($this->uri->segment(3) != 1) $this->messages->set_message('green', 'Zdjęcie baneru poprawnie usunięte');
		redirect(base_url().'admin/baner', 'refresh');
	}
	
	function setbanerglownyphotosorder(){
		$this->load->model('Baner_glowny_model');
			
		$this->Baner_glowny_model->setbanerglownyphotosorder($this->input->post('baner'));
	}
	
	function slider(){
		$this->load->model('Admin_model');
		$top_data['mainmenu'] = "Zarządzanie kontenerami";
		$top_data['submenu'] = "Slider";
		$top_data['user_link'] = $this->Admin_model->getuserlink($this->session->userdata('uzytkownik_id'));
		$top_data['user_submenu'] = '';
		$top_data['multi'] = $this->Admin_model->checkmultilanguser($this->session->userdata('uzytkownik_id'));
		$top_data['langs'] = $this->Admin_model->getlangsuser($this->session->userdata('uzytkownik_id'));
		$this->load->view('localAdmin/top_view', $top_data);
		
		$this->load->model('Slider_glowny_model');
		$data['adres'] = $this->Admin_model->get_user_pagename($this->session->userdata('uzytkownik_id'));
		$data['photos'] = $this->Slider_glowny_model->getsliderglownyphotos($this->session->userdata('uzytkownik_id'));
		$data['allpages'] = $this->Slider_glowny_model->checkallpages($this->session->userdata('uzytkownik_id'));
		
		$this->load->view('localAdmin/content_top_view');
		$this->load->view('localAdmin/slider_glowny_view', $data);
		$this->load->view('localAdmin/content_bottom_view');
		
		$this->load->view('localAdmin/bottom_view');
	}
	
	function sliderglownyustawienia(){
		$this->load->model('Slider_glowny_model');
		$this->Slider_glowny_model->sliderglownyustawienia($this->session->userdata('uzytkownik_id'), $this->input->post('checkslider'));
		redirect(base_url().'admin/slider');
	}
	
	function addsliderglownyphoto(){
		$this->load->model('Slider_glowny_model');
		$message = '';
		$img = '';
		$ret = $this->Slider_glowny_model->addsliderglownyphoto($this->input->post('user_id', TRUE), $this->input->post('foto_x', TRUE), $this->input->post('foto_y', TRUE),
			$this->input->post('header', TRUE), $this->input->post('plik', TRUE), $this->input->post('change_size'), $this->input->post('link'));
		if($ret == false) {
			$img = '';
			$message = 'Podaj plik w odpowiednim formacie (JPEG, GIF, PNG)';
			$this->messages->set_message('red', 'Dodawanie nowego zdjęcia slidera. Podaj plik w odpowiednim formacie (JPEG, GIF, PNG)');
		} else {
			$img = $ret;
			$message = 'Nowe zdjęcie slidera poprawnie dodane';
			$this->messages->set_message('green', 'Nowe zdjęcie slidera poprawnie dodane');
		}
		if($this->uri->segment(3) == 1){
			$file = $_FILES['plik'];
			$n = $file['name'];
			//echo '{"name":"'.$n.'","message":"'.$message.'","img":"'.$img.'"}';
			echo $img.'';
			return;
		} else {
			redirect(base_url().'admin/slider', 'refresh');
		}
	}
	
	function getsliderglownydata($id){
		$this->load->model('Slider_glowny_model');
		$slider = $this->Slider_glowny_model->getsliderglowny($id);
		
		if($slider){
			$data['header'] = $slider->slider_glowny_header;
			$data['link'] = $slider->slider_glowny_link;
		} else $data = NULL;
		
		$json = json_encode($data);
		echo $json;
	}
	
	function edytujsliderglowny(){
		$this->load->model('Slider_glowny_model');
		$this->Slider_glowny_model->edytujsliderglowny($this->input->post('slider_id'), $this->input->post('header'), $this->input->post('link'));
		
		$this->messages->set_message('green', 'Zdjęcie slidera poprawnie edytowane');
		redirect(base_url().'admin/slider');
	}
	
	function cropsliderglowny(){
		$this->load->model('Slider_glowny_model');
		$this->Slider_glowny_model->cropslider($this->input->post('foto'), $this->input->post('x'), $this->input->post('y'),
			$this->input->post('x2'), $this->input->post('y2'), $this->input->post('h'), $this->input->post('w'));
		echo '1';		
	}
	
	function removesliderglownyphoto(){
		//$this->load->model('Modul_model');
		$this->load->model('Slider_glowny_model');
			
		$this->Slider_glowny_model->removesliderglownyphoto($this->input->post("id", TRUE), $this->input->post("name", TRUE));
			
		if($this->uri->segment(3) != 1) $this->messages->set_message('green', 'Zdjęcie slidera poprawnie usunięte');
		redirect(base_url().'admin/slider', 'refresh');
	}
	
	function setsliderglownyphotosorder(){ 
		$this->load->model('Slider_glowny_model');
			
		$this->Slider_glowny_model->setsliderglownyphotosorder($this->input->post('slider'));
	}
	
	function statystyki(){
		$this->load->model('Admin_model');
		$top_data['mainmenu'] = "Statystyki";
		$top_data['submenu'] = "";
		$top_data['user_link'] = $this->Admin_model->getuserlink($this->session->userdata('uzytkownik_id'));
		$top_data['user_submenu'] = '';
		$top_data['multi'] = $this->Admin_model->checkmultilanguser($this->session->userdata('uzytkownik_id'));
		$top_data['langs'] = $this->Admin_model->getlangsuser($this->session->userdata('uzytkownik_id'));
		$this->load->view('localAdmin/top_view', $top_data);
		
		$data = array();
		
		$this->load->view('localAdmin/content_top_view');
		$this->load->view('localAdmin/statystyki_view', $data);
		$this->load->view('localAdmin/content_bottom_view');
		
		$this->load->view('localAdmin/bottom_view');
	}
	
	
	
	
	

	
	
	
	/*
	function displayMainTree($node) {
		if(!$node->getNodeChildsCount()) return;
		$nodes = $node->getNodeFirtLevelChilds();
		if($node->path=="root") $this->drzewo.= "<ul id='browser' class='filetree'> "; else 	$this->drzewo.= "<ul id='folder".$node->id."'>";
		//$this->drzewo.= "<ul>";
		foreach($nodes as $singleNode) {
			if($singleNode->getNodeChildsCount()) $isNextLevel="class='folder'"; else $isNextLevel="class='file'";
			$this->drzewo.= "<li><span id=".$singleNode->id." ".$isNextLevel."><a href='".base_url()."admin/wyswietl/".$singleNode->id."' >".$singleNode->nodeData['name']."</a></span>";
			if($singleNode->getNodeChildsCount()) $this->displayMainTree($singleNode);
			$this->drzewo.= "</li>";
		}
		$this->drzewo.= "</ul>";
	}
	*/
	
	function displayMainTree2($node, $pad = 0) {
		if(!$node->getNodeChildsCount()) return;
		$nodes = $node->getNodeFirtLevelChilds();
		
		
		foreach($nodes as $singleNode) {
			//if((++$this->lp % 2) == 0) $alt_row =  "class='alternate-row'"; else $alt_row= "";
			++$this->lp;
			if($pad == 0) $alt_row =  "class='alternate-row first_child'"; else $alt_row= "";
			$this->drzewo.="<tr ".$alt_row."><td>".$this->lp.".</td><td><span class='tableTreeTitle' style='padding-left: ".$pad."px;'><span style='font-size: 20px; padding-right: 2px;'>".($pad>0?'⌞':'')."</span><a href='".base_url()."admin/wyswietl/".$singleNode->id."'>".$singleNode->nodeData['name']."</a></span></td>
			<td align='right' style='padding-right: 0;'><span class='operacje'>
				<a alt='W górę' title='W górę' href='".base_url()."admin/moveup/".$singleNode->id."'><img src='".base_url()."images/icon/up.png'></a>
				<a alt='W dół' title='W dół' href='".base_url()."admin/movedown/".$singleNode->id."'><img src='".base_url()."images/icon/download_1.png'></a>
				<a alt='Edytuj' title='Edytuj' href='".base_url()."admin/wyswietl/".$singleNode->id."'><img src='".base_url()."images/icon/edit.png'></a>";
				if( ! $this->blokada_stron || $pad > 0){
					$this->drzewo .= "<a id='".$singleNode->id."' class='dodaj_podstrone_' alt='Dodaj podstrone' title='Dodaj podstrone' href='".base_url()."admin/wyswietl/".$singleNode->id."'><img src='".base_url()."images/icon/add_to_folder.png'></a>";
				}
				$this->drzewo .= "<form class='usundrzewo' style='display: inline;' action='".base_url()."admin/deletenode' method='post'>
					<input name='id' type='hidden' value='".$singleNode->id."' id='nodeIdDelete' />
					<input name='action' type='hidden' value='delete'  />
					<input type='hidden' name='redi' value='".$this->uri->segment(2)."/".$this->uri->segment(3)."' />
					<input title='Usuń' type='image' border=0 src='".base_url()."images/icon/delete.png'>
				</form>
			
				</span>
			</td></tr>";
			
			if($singleNode->getNodeChildsCount()) $this->displayMainTree2($singleNode, $pad + 20);
			
		}
		
	}
	
	
	
	
	function index() {
		
		if($this->session->userdata("zalogowany")==TRUE/* && $this->session->userdata("admin")==0*/) {
			
			$this->load->model('Admin_model');
			
			
					
			
			$top_data['mainmenu'] = "Zarządzaj stroną";
			$top_data['submenu'] = "Zarządzaj stroną";
			$top_data['user_link'] = $this->Admin_model->getuserlink($this->session->userdata('uzytkownik_id'));
			$top_data['user_submenu'] = '';
			$top_data['multi'] = $this->Admin_model->checkmultilanguser($this->session->userdata('uzytkownik_id'));
			$top_data['langs'] = $this->Admin_model->getlangsuser($this->session->userdata('uzytkownik_id'));
			$this->load->view('localAdmin/top_view', $top_data); //*******************
			
			$this->load->model('Tree_model');
			
			$this->session->set_userdata(array('lastPage' => ''));
			$rootId = $this->Tree_model->getRootId($this->session->userdata("uzytkownik_id"));
			$this->drzewo = "<ul id='browser' class='filetree' style='float:left' >Zarządzaj podstronami:
<li><span id ='".$rootId."' class='rootId folder'><a href='".base_url()."' >root</a></span>";
			$root = new node($this->Tree_model, $rootId);
			$this->displayTree($root);
			$this->drzewo.="</li>
</ul>";
			$data['tree'] = $this->drzewo;
			$this->drzewo = '';
			
			//
			
			/*$this->drzewo = "<ul style='float:left' >";
			$root = new node($this->Tree_model, $rootId);
			$this->displayMainTree($root);
			$this->drzewo.="</ul>";*/
			
			$this->drzewo .= "<table id='product-table' class='mainTree'>
			<tr><th class='table-header-check'></th><th class='table-header-repeat line-left minwidth-1'><span>Tytuł</span></th align='right'>
			<th class='table-header-options line-left minwidth-1'><span>Operacje</span></th></tr>";
			$root = new node($this->Tree_model, $rootId);
			$this->displayMainTree2($root, 0);
			$this->drzewo .= "</table>";
			$data['mainTree'] = $this->drzewo;
			
			$this->drzewo .= "";
			$his->lp = 0;
			
			$data['blokada_stron'] = $this->blokada_stron;
			
			$this->load->view('localAdmin/content_top_view', $data);
			$this->load->view('localAdmin/admin_klient_view', $data);
			$this->load->view('localAdmin/content_bottom_view', $data);
			
			
			$dialog_data['local_templates'] = $this->getLocalTemplates($this->session->userdata('uzytkownik_id'));
			$dialog_data['default_article_template'] = $this->Admin_model->getarticletemplate($this->session->userdata('uzytkownik_id'));
			$this->load->view('localAdmin/dialog_view', $dialog_data);
			$this->load->view('localAdmin/bottom_view'); //********************
						
		} else $this->load->view('localAdmin/login_view');
		//echo dirname(__FILE__);
		/*$this->load->library('messages');
		if($this->uri->segment(3)){
			$this->messages->set_message('blue', $this->uri->segment(3));
		} else echo $this->messages->get_message('blue');*/
	}
	
	/***
	function displayMainTree2($node, $pad) {
		if(!$node->getNodeChildsCount()) return;
		$nodes = $node->getNodeFirtLevelChilds();
		
		
		foreach($nodes as $singleNode) {
			$this->drzewo.="<tr><td><span class='tableTreeTitle' style='padding-left: ".$pad."px;'>".$singleNode->nodeData['name']."</span></td>
			<td align='right'>
				<a alt='W górę' title='W górę' href='".base_url()."admin/moveup/".$singleNode->id."'><img src='".base_url()."images/move_up.png'></a>
				<a alt='W dół' title='W dół' href='".base_url()."admin/movedown/".$singleNode->id."'><img src='".base_url()."images/move_down.png'></a>
				<a alt='Edytuj' title='Edytuj' href='".base_url()."admin/wyswietl/".$singleNode->id."'><img src='".base_url()."images/page_white_edit.png'></a>
				<form style='display: inline;' action='".base_url()."admin/deletenode' method='post'>
					<input name='id' type='hidden' value='".$singleNode->id."' id='nodeIdDelete' />
					<input name='action' type='hidden' value='delete'  />
					<input type='hidden' name='redi' value='".$this->uri->segment(2)."/".$this->uri->segment(3)."' />
					<input type='image' border=0 src='".base_url()."images/page_white_delete.png'>
				</form>
			
				
			</td></tr>";
			
			if($singleNode->getNodeChildsCount()) $this->displayMainTree2($singleNode, $pad + 20);
			
		}
		
	}
	
	
	***/
	
	
	function getNodeData($id){
		
		$this->load->model('Tree_model');
		
		$nodeToEdit = new node($this->Tree_model, $id);
		$data['name'] = $nodeToEdit->nodeData['name'];
		$data['title'] = $nodeToEdit->nodeData['title'];
		$data['description'] = $nodeToEdit->nodeData['description'];
		$data['text'] = $nodeToEdit->nodeData['text'];
		$data['published'] = $nodeToEdit->nodeData['published'];
		$data['sitemap'] = $nodeToEdit->nodeData['sitemap'];
		$data['link'] = $nodeToEdit->nodeData['link'];
		$data['menu'] = $nodeToEdit->nodeData['menu'];
		$data['mini'] = $nodeToEdit->nodeData['mini'];
		$data['template'] = $nodeToEdit->nodeData['template'];
		$data['link_val'] = $nodeToEdit->nodeData['link_val'];
		$data['photo'] = $nodeToEdit->nodeData['photo'];
		$data['menu2'] = $nodeToEdit->nodeData['menu2'];

		$json = json_encode($data);
		echo $json;
		
	}
}	

