<?php



class Administrator extends Controller {

	public $drzewo = '';

	function Administrator() {
		parent::Controller();
		
		//require APPPATH.'config/database.php';
		//echo $db['default']['hostname'];
		
		$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->helper('cookie');
		if($this->session->userdata("zalogowany")==FALSE || $this->session->userdata("admin")!=1) redirect(base_url(), 'refresh');
	}
	
	
	
	function index(){
		$this->load->model('Administrator_model');
		$top_data['mainmenu'] = "Administracja";
		$top_data['submenu'] = "Użytkownicy";
		
		$this->load->library('pagination');
		$config['base_url'] = base_url().'administrator/index/'.(int)$this->uri->segment(3).'/';
		$config['per_page'] = '10';
		$config['uri_segment'] = 4;
		/*$config['full_tag_open'] = '<p class="admin_pagination">';
		$config['full_tag_close'] = '</p>';*/
		$config['num_tag_open'] = '<span class="admin_pagination">';
		$config['num_tag_close'] = '</span>';
		$config['cur_tag_open'] = '<span class=" active_page">';
		$config['cur_tag_close'] = '</span>';
		
		$config['next_link'] = '<span class="admin_pagination_next"></span>';
		$config['next_tag_open'] = '';
		$config['next_tag_close'] = '';
		
		$config['prev_link'] = '<span class="admin_pagination_prev"></span>';
		$config['prev_tag_open'] = '';
		$config['prev_tag_close'] = '';
		
		$config['first_link'] = 'Początek';
		$config['first_tag_open'] = '<span class="admin_pagination">';
		$config['first_tag_close'] = '</span>';
		
		$config['last_link'] = 'Koniec';
		$config['last_tag_open'] = '<span class="admin_pagination">';
		$config['last_tag_close'] = '</span>';

		$config['num_links'] = 3;
		$config['total_rows'] = $this->Administrator_model->get_users_totalrows();
		
		$this->pagination->initialize($config);
		
		$this->load->view('headAdmin/administrator_top_view', $top_data);
		
		//$data['users'] = $this->Administrator_model->get_users();	
		$data['users'] = $this->Administrator_model->get_users_by_page((int)$this->uri->segment(4), $config['per_page'], (int)$this->uri->segment(3));
			
		$this->load->view('headAdmin/administrator_view', $data);
		$this->load->view('localAdmin/bottom_view');
	}

	function zaloguj_jako($id){
		//$this->session->sess_destroy();
		
		$this->session->unset_userdata('uzytkownik');
		$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->load->helper('cookie');
		delete_cookie("autologowanie");
		
		$this->load->model('Administrator_model');
		$this->Administrator_model->zaloguj_jako($id);
		

		redirect(base_url());
	}
	
	function wyloguj(){
		$this->session->unset_userdata('uzytkownik');
		$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');

		redirect(base_url(), 'refresh');
	}
	
	function klienci(){
		//if($this->session->userdata("zalogowany")==FALSE || $this->session->userdata("admin")!=1) redirect(base_url(), 'refresh');

		$this->load->model('Administrator_model');
		$top_data['mainmenu'] = "Administracja";
		$top_data['submenu'] = "Użytkownicy";
		
		$this->load->view('headAdmin/administrator_top_view', $top_data);
		
		$data['form'] = 0;
		if($this->uri->segment(3)){
			//$data['form'] = 1;
			$data['user'] = NULL;
			if($this->uri->segment(3) == 'nowy') {
				//$data['nowy'] = 1;
				$data['users'] = $this->Administrator_model->get_users();
				$this->load->view('headAdmin/klienci_view', $data);
			} else {
				//$data['nowy'] = 0;
				$user = $this->Administrator_model->get_user($this->uri->segment(3));
				$data['user'] = $user;
				$this->load->view('headAdmin/klienci_edit_view', $data);
			}
		} else {redirect(base_url().'administrator', 'refresh');}
		
		
		
		$this->load->view('localAdmin/bottom_view');
	}
	
	function klient_dodaj(){
		//if($this->session->userdata("zalogowany")==FALSE || $this->session->userdata("admin")!=1) redirect(base_url(), 'refresh');
		
		$this->load->model('Administrator_model');
		$this->load->library('email');
		if(($this->Administrator_model->add_user()) > 0) {
			//$this->session->set_userdata('green', 'Użytkownik poprawnie dodany');
			//$cookie = array('name'   => 'green','value'  => 'Użytkownik poprawnie dodany','expire' => '865000');
			//set_cookie($cookie);
			$this->messages->set_message('green', 'Użytkownik poprawnie dodany');
		} else {
			//$this->session->set_userdata('red', 'Podczas dodawania użytkownika mógł wystąpić błąd');
			//$cookie = array('name'   => 'red','value'  => 'Podczas dodawania użytkownika mógł wystąpić błąd','expire' => '865000');
			//set_cookie($cookie);
			$this->messages->set_message('red', 'Podczas dodawania użytkownika mógł wystąpić błąd');
		}
		redirect(base_url().'administrator', 'refresh');
	}
	
	function klient_edytuj($klient){
		//if($this->session->userdata("zalogowany")==FALSE || $this->session->userdata("admin")!=1) redirect(base_url(), 'refresh');
		
		$this->load->model('Administrator_model');
			
		if($this->Administrator_model->edit_user($klient) > 0){
			//$cookie = array('name'   => 'green','value'  => 'Dane zaktualizowane','expire' => '865000');
			//set_cookie($cookie);
			$this->messages->set_message('green', 'Dane zaktualizowane');
		} else {
			//$cookie = array('name'   => 'red','value'  => 'Podczas edycji danych mógł wystąpić błąd','expire' => '865000');
			//set_cookie($cookie);
			$this->messages->set_message('red', 'Podczas edycji danych mógł wystąpić błąd');
		}
		redirect(base_url().'administrator/klienci/'.$klient, 'refresh');
	}
	
	function klient_usun($klient){
		//if($this->session->userdata("zalogowany")==FALSE || $this->session->userdata("admin")!=1) redirect(base_url(), 'refresh');
		
		$this->load->model('Administrator_model');
			
		if($this->Administrator_model->delete_user($klient)){
			//$cookie = array('name'   => 'green','value'  => 'Użytkownik usunięty','expire' => '865000');
			//set_cookie($cookie);
			$this->messages->set_message('green', 'Użytkownik usunięty');
		} else {
			
		}
		redirect(base_url().'administrator/', 'refresh');
	}
	
	function klient_blokuj($klient, $blokada){
		//if($this->session->userdata("zalogowany")==FALSE || $this->session->userdata("admin")!=1) redirect(base_url(), 'refresh');
		
		$this->load->model('Administrator_model');
		if($this->Administrator_model->block_user($klient, $blokada)){
			//$cookie = array('name'   => 'green','value'  => 'Użytkownik poprawnie zablokowany/odblokowany','expire' => '865000');
			//set_cookie($cookie);
			$this->messages->set_message('green', 'Użytkownik poprawnie zablokowany/odblokowany');
		} else {
			//$cookie = array('name'   => 'red','value'  => 'Podczas blokowania/odblokowania użytkownika mógł wystąpić błąd','expire' => '865000');
			//set_cookie($cookie);
			$this->messages->set_message('red', 'Podczas blokowania/odblokowania użytkownika mógł wystąpić błąd');
		}
		redirect(base_url().'administrator/');
	}
	
	function klient_blokuj_strony($klient, $blokada){
		$this->load->model('Administrator_model');
		if($this->Administrator_model->block_new_pages($klient, $blokada)){
			$this->messages->set_message('green', 'Dodawanie stron poprawnie zablokowane/odblokowane');
		} else {
			$this->messages->set_message('red', 'Podczas blokowania/odblokowania dodawania stron mógł wystąpić błąd');
		}
		redirect(base_url().'administrator/');
	}
	
	function ustawienia(){
		//if($this->session->userdata("zalogowany")==FALSE || $this->session->userdata("admin")!=1) redirect(base_url(), 'refresh');
			
		$this->load->model('Administrator_model');
		$data['user'] = $this->Administrator_model->get_user($this->session->userdata('uzytkownik_id'))->row();
							
		$top_data['mainmenu'] = "Ustawienia CMS";
		$top_data['submenu'] = "Ustawienia";
		
		$this->load->view('headAdmin/administrator_top_view', $top_data);
		$this->load->view('headAdmin/administrator_ustawienia_view', $data);
		$this->load->view('localAdmin/bottom_view');
	}
	
	function edituser(){
		//if($this->session->userdata("zalogowany")==FALSE || $this->session->userdata("admin")!=1) redirect(base_url(), 'refresh');

		$this->load->library('validation');
		$rules['name']		= "required";
		$rules['mail']		= "required";
		
		$this->validation->set_rules($rules);
			
		if ($this->validation->run() != TRUE){
			//$this->session->set_userdata(array('red' => 'Edycja danych użytkownika. Wypełnij wymagane pola "Login", "Adres e-mail"'));
			//$cookie = array('name'   => 'red','value'  => 'Edycja danych użytkownika. Wypełnij wymagane pola "Login", "Adres e-mail"','expire' => '865000');
			//set_cookie($cookie);
			$this->messages->set_message('red', 'Edycja danych użytkownika. Wypełnij wymagane pola "Login", "Adres e-mail"');
			redirect(base_url().'administrator/ustawienia', 'refresh');		
		}
		
		$this->load->model('Admin_model');
		if($this->Admin_model->edituser($this->session->userdata('uzytkownik_id'), $this->input->post('name', TRUE), $this->input->post('mail', TRUE), $this->input->post('pagename', TRUE)) > 0) {
			//$cookie = array('name'   => 'green','value'  => 'Dane zaktualizowane','expire' => '865000');
			//set_cookie($cookie);
			$this->messages->set_message('green', 'Dane zaktualizowane');
		} else {
			//$cookie = array('name'   => 'red','value'  => 'Podczas aktualizowania danych mógł wystąpić błąd','expire' => '865000');
			//set_cookie($cookie);
			$this->messages->set_message('red', 'Podczas aktualizowania danych mógł wystąpić błąd');
		}
		redirect(base_url().'administrator/ustawienia', 'refresh');		
	}
	
	function zmiana_hasla(){
		//if($this->session->userdata("zalogowany")==FALSE || $this->session->userdata("admin")!=1) redirect(base_url(), 'refresh');
		//echo $this->session->userdata("uzytkownik_id");
		$top_data['mainmenu'] = "Ustawienia CMS";
		$top_data['submenu'] = "Zmiana hasła";
		
		$this->load->view('headAdmin/administrator_top_view', $top_data);
		$this->load->view('headAdmin/administrator_zmiana_hasla_view');
		$this->load->view('localAdmin/bottom_view');		
	}
	
	function changepass(){
		//if($this->session->userdata("zalogowany")==FALSE || $this->session->userdata("admin")!=1) redirect(base_url(), 'refresh');
		
		$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->session->set_userdata(array('red' => 'Zmiana hasła. Wypełnij wymagane pola "Stare hasło", "Nowe hasło", "Powtórz nowe hasło"'));
			//$cookie = array('name'   => 'red','value'  => 'Zmiana hasła. Wypełnij wymagane pola "Stare hasło", "Nowe hasło", "Powtórz nowe hasło"','expire' => '865000');
			//set_cookie($cookie);
			$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().'administrator/zmiana_hasla', 'refresh');	
		}
		
		if($this->Admin_model->checkpass($this->session->userdata('uzytkownik_id'), $this->input->post('old_pass')) != TRUE) {
			//$this->session->set_userdata(array('red' => 'Zmiana hasła. Podaj prawidłowe "Stare hasło"'));
			//$cookie = array('name'   => 'red','value'  => 'Zmiana hasła. Podaj prawidłowe "Stare hasło"','expire' => '865000');
			//set_cookie($cookie);
			$this->messages->set_message('red', 'Zmiana hasła. Podaj prawidłowe "Stare hasło"');
			redirect(base_url().'administrator/zmiana_hasla', 'refresh');
		}
			
		$rules1['new_pass1'] = "matches[new_pass2]";
		$this->validation->set_rules($rules1);
		if($this->validation->run() != TRUE){
			//$this->session->set_userdata(array('red' => 'Zmiana hasła. Pola "Nowe hasło" i "Powtórz nowe hasło" powinny być takie same'));
			//$cookie = array('name'   => 'red','value'  => 'Zmiana hasła. Pola "Nowe hasło" i "Powtórz nowe hasło" powinny być takie same','expire' => '865000');
			//set_cookie($cookie);
			$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().'administrator/zmiana_hasla', 'refresh');	
		}
		
		if($this->Admin_model->changepass($this->session->userdata('uzytkownik_id'), $this->input->post('new_pass1')) > 0){
			//$cookie = array('name'   => 'green','value'  => 'Dane zaktualizowane','expire' => '865000');
			//set_cookie($cookie);
			$this->messages->set_message('green', 'Dane zaktualizowane');
		} else {
			//$cookie = array('name'   => 'red','value'  => 'Podczas aktualizowania danych mógł wystąpić błąd','expire' => '865000');
			//set_cookie($cookie);
			$this->messages->set_message('red', 'Podczas aktualizowania danych mógł wystąpić błąd');
		}
		redirect(base_url().'administrator/zmiana_hasla', 'refresh');	
	}
	
	function aktywnosc_uzytkownikow(){
		//if($this->session->userdata("zalogowany")==FALSE || $this->session->userdata("admin")!=1) redirect(base_url(), 'refresh');
		
		$this->load->model('Administrator_model');
		
		$this->load->library('pagination');
		$config['base_url'] = base_url().'administrator/aktywnosc_uzytkownikow/'.(int)$this->uri->segment(3).'/'.(int)$this->uri->segment(4);
		$config['per_page'] = '20';
		$config['uri_segment'] = 5;
		$config['num_tag_open'] = '<span class="admin_pagination">';
		$config['num_tag_close'] = '</span>';
		$config['cur_tag_open'] = '<span class=" active_page">';
		$config['cur_tag_close'] = '</span>';
		
		$config['next_link'] = '<span class="admin_pagination_next"></span>';
		$config['next_tag_open'] = '';
		$config['next_tag_close'] = '';
		
		$config['prev_link'] = '<span class="admin_pagination_prev"></span>';
		$config['prev_tag_open'] = '';
		$config['prev_tag_close'] = '';
		
		$config['first_link'] = 'Początek';
		$config['first_tag_open'] = '<span class="admin_pagination">';
		$config['first_tag_close'] = '</span>';
		
		$config['last_link'] = 'Koniec';
		$config['last_tag_open'] = '<span class="admin_pagination">';
		$config['last_tag_close'] = '</span>';
		
		$config['num_links'] = 3;
		
		$data['users'] = $this->Administrator_model->get_users(true);
		
		if((int)$this->uri->segment(3) == 0) {
			if((int)$this->uri->segment(4) == 0) {
				$data['stats'] = $this->Administrator_model->getstats((int)$this->uri->segment(5), $config['per_page']);
				$data['log'] = NULL;
				$config['total_rows'] = $this->Administrator_model->getstats_totalrows();
			} else
			if((int)$this->uri->segment(4) == 1) {
				$data['log'] = $this->Administrator_model->getactions((int)$this->uri->segment(5), $config['per_page']);
				$data['stats'] = NULL;
				$config['total_rows'] = $this->Administrator_model->getaction_totalrows();
			} else {
				$data['stats'] = $data['log'] = NULL;
				$config['total_rows'] = 0;
			}
		} else {
			if((int)$this->uri->segment(4) == 0) {
				$data['stats'] = $this->Administrator_model->getuserstats((int)$this->uri->segment(3), NULL, (int)$this->uri->segment(5), $config['per_page']);
				$config['total_rows'] = $this->Administrator_model->getuserstats_totalrows((int)$this->uri->segment(3));
				$data['log'] = NULL;
			} else
			if((int)$this->uri->segment(4) == 1){
				$data['log'] = $this->Administrator_model->getlog((int)$this->uri->segment(3), NULL, (int)$this->uri->segment(5), $config['per_page']);
				$config['total_rows'] = $this->Administrator_model->getlog_totalrows((int)$this->uri->segment(3));
				$data['stats'] = NULL;
			} else {
				$data['stats'] = $data['log'] = NULL;
				$config['total_rows'] = 0;
			}
		}
		
		

		$this->pagination->initialize($config); 
		
		/*
		if($this->uri->segment(3) && (int)$this->uri->segment(3) > 0) {
			$data['stats'] = $this->Administrator_model->getuserstats($this->uri->segment(3), $this->uri->segment(4));
			$data['log'] = $this->Administrator_model->getlog($this->uri->segment(3), $this->uri->segment(4));
			
		} else if($this->uri->segment(3) == 'dzien'){
			$data['stats'] = $this->Administrator_model->getuserstats(null, $this->uri->segment(4));
			$data['log'] = $this->Administrator_model->getlog(null, $this->uri->segment(4));
		} else {
			$data['stats'] = $this->Administrator_model->getstats();
			$data['log'] = null;
		}*/
		
		$top_data['mainmenu'] = "Administracja";
		$top_data['submenu'] = "Aktywność użytkowników";
		
		$this->load->view('headAdmin/administrator_top_view', $top_data);
		$this->load->view('headAdmin/administrator_aktywnosc_view', $data);
		$this->load->view('localAdmin/bottom_view');
		
	}
	
	function getaktywnosc(){
		//if($this->session->userdata("zalogowany")==FALSE || $this->session->userdata("admin")!=1) redirect(base_url(), 'refresh');
		redirect(base_url().'administrator/aktywnosc_uzytkownikow/'.$this->input->post('user').'/'.$this->input->post('type'));
	}
	
	function klient_wybierz_skrypty($klient){
		//if($this->session->userdata("zalogowany")==FALSE || $this->session->userdata("admin")!=1) redirect(base_url(), 'refresh');
		
		$this->load->model('Administrator_model');
		$top_data['mainmenu'] = "Administracja";
		$top_data['submenu'] = "Użytkownicy";
		
		$this->load->view('headAdmin/administrator_top_view', $top_data);
		
		//$data['users'] = $this->Administrator_model->get_users();
		$data['plugins'] = $this->Administrator_model->get_plugins();
		$data['user_plugins'] = $this->Administrator_model->get_user_plugins($this->uri->segment(3));
				
		$this->load->view('headAdmin/administrator_wybierz_js_view', $data);
		$this->load->view('localAdmin/bottom_view');
		
	}
	
	function addplugin(){
		//if($this->session->userdata("zalogowany")==FALSE || $this->session->userdata("admin")!=1) redirect(base_url(), 'refresh');
		
		$this->load->model('Administrator_model');
		$this->Administrator_model->addplugin($this->input->post('name'), $this->input->post('katalog'));
		
		$this->messages->set_message('green', 'Nowy plugin został dodany');
		
		redirect(base_url()."administrator/ustawienia_plugin");
	}
	
	function setpluginsforuser(){
		//if($this->session->userdata("zalogowany")==FALSE || $this->session->userdata("admin")!=1) redirect(base_url(), 'refresh');
		
		$this->load->model('Administrator_model');
		$this->Administrator_model->setpluginsforuser($this->input->post('user_id'), $this->input->post('plugins'));
		
		$this->messages->set_message('green', 'Pluginy zostały wybrane');
		
		redirect(base_url()."administrator/klient_wybierz_skrypty/".$this->input->post('user_id'));
	}
	
	function setpluginsorder(){
		//if($this->session->userdata("zalogowany")==FALSE || $this->session->userdata("admin")!=1) redirect(base_url(), 'refresh');
			
		$this->load->model('Administrator_model');
			
		$this->Administrator_model->setpluginsorder($this->input->post('plugin'));
	}
	
	function dodaj_link($klient){
		//if($this->session->userdata("zalogowany")==FALSE || $this->session->userdata("admin")!=1) redirect(base_url(), 'refresh');
		
		$this->load->model('Administrator_model');
		$top_data['mainmenu'] = "Administracja";
		$top_data['submenu'] = "Użytkownicy";
		
		$this->load->view('headAdmin/administrator_top_view', $top_data);
		
		$data['link'] = $this->Administrator_model->getlink($klient);
		
		$this->load->view('headAdmin/administrator_link_view', $data);
		$this->load->view('localAdmin/bottom_view');
	}
	
	function addlink(){
		//if($this->session->userdata("zalogowany")==FALSE || $this->session->userdata("admin")!=1) redirect(base_url(), 'refresh');
		
		$this->load->model('Administrator_model');
		$this->Administrator_model->addlink($this->input->post('user_id'), $this->input->post('name'), $this->input->post('adres'));
		
		$this->messages->set_message('green', 'Link został dodany');
		
		redirect(base_url()."administrator/dodaj_link/".$this->input->post('user_id'));
	}
	
	function updatelink(){
		//if($this->session->userdata("zalogowany")==FALSE || $this->session->userdata("admin")!=1) redirect(base_url(), 'refresh');
		
		$this->load->model('Administrator_model');
		$this->Administrator_model->updatelink($this->input->post('user_id'), $this->input->post('name'), $this->input->post('adres'));
		
		$this->messages->set_message('green', 'Link został zaktualizowany');
		
		redirect(base_url()."administrator/dodaj_link/".$this->input->post('user_id'));
	}
	
	function ustawienia_plugin(){
		//if($this->session->userdata("zalogowany")==FALSE || $this->session->userdata("admin")!=1) redirect(base_url(), 'refresh');
		
		$this->load->model('Administrator_model');
		$top_data['mainmenu'] = "Ustawienia CMS";
		$top_data['submenu'] = "Ustawienia plugin";
		
		$this->load->view('headAdmin/administrator_top_view', $top_data);
		
		$data['plugins'] = $this->Administrator_model->get_plugins();
		$this->load->view('headAdmin/administrator_plugin_view', $data);
		$this->load->view('localAdmin/bottom_view');
		
	}
	
	function ustawienia_szablonow(){
		
		$this->load->model('Administrator_model');
		$top_data['mainmenu'] = "Ustawienia CMS";
		$top_data['submenu'] = "Ustawienia szablonów";
		
		$this->load->view('headAdmin/administrator_top_view', $top_data);
		
		$data['users'] = $this->Administrator_model->get_users();
		$data['templates'] = $this->Administrator_model->getglobaltemplates();
		$data['article_templates'] = $this->Administrator_model->getarticletemplates();
		
		$this->load->view('headAdmin/administrator_szablon_view', $data);
		$this->load->view('localAdmin/bottom_view');
		
	}
	
	function addglobaltemplate(){
		$this->load->model('Administrator_model');
		$this->Administrator_model->addglobaltemplate($this->input->post('name'), $this->input->post('desc'), $this->input->post('folder'), $this->input->post('photo'), $this->input->post('enabled'));
		
		$this->messages->set_message('green', 'Nowy szablon został dodany');
		
		redirect(base_url().'administrator/ustawienia_szablonow');
	}
	
	function editglobaltemplate(){
		$this->load->model('Administrator_model');
		$this->Administrator_model->editglobaltemplate($this->input->post('template_id'), $this->input->post('name'), $this->input->post('desc'), $this->input->post('folder'), $this->input->post('old_folder'), $this->input->post('enabled'), $_FILES['photo']);
		
		$this->messages->set_message('green', 'Opis szablonu poprawnie edytowany');
		redirect(base_url().'administrator/ustawienia_szablonow');
	}
	
	function addarticletemplate(){
		$this->load->model('Administrator_model');
		$this->Administrator_model->addarticletemplate($this->input->post('name'), $this->input->post('desc'), $this->input->post('folder'), $this->input->post('filename'), $this->input->post('photo'), $this->input->post('user_id'));
		
		$this->messages->set_message('green', 'Nowy szablon dla artykułu dodany');
		redirect(base_url().'administrator/ustawienia_szablonow');
	}
	
	function editarticletemplate(){
		$this->load->model('Administrator_model');
		$this->Administrator_model->editarticletemplate($this->input->post('templateA_id'), $this->input->post('name'), $this->input->post('desc'), $this->input->post('folder'), $this->input->post('old_folder'), $this->input->post('user_id'), $_FILES['photo']);
		
		$this->messages->set_message('green', 'Opis szablonu poprawnie edytowany');
		redirect(base_url().'administrator/ustawienia_szablonow');
	}
	
	function wyslij_haslo($klient){
		$this->load->model('Administrator_model');
		$this->load->library('email');
		$r = $this->Administrator_model->wyslij_haslo($klient);
		if($r == 1)	$this->messages->set_message('green', 'Hasło zostało wysłane'); else $this->messages->set_message('red', 'Wystąpił błąd'); 
		redirect(base_url().'administrator');
	}
	
	function statystyki(){
		$this->load->model('Administrator_model');
		$top_data['mainmenu'] = "Administracja";
		$top_data['submenu'] = "Statystyki";
		
		$this->load->view('headAdmin/administrator_top_view', $top_data);
		
		$this->load->view('headAdmin/administrator_statystyki_view');
		
		/*echo '
<iframe frameborder=\"0\" src="'.base_url().'dashboard" width="1020 px;" height="600px;">

</iframe>';*/
		$this->load->view('localAdmin/bottom_view');
	}
}	

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
