<?php

class Main extends Controller {
  
function main(){
     parent::Controller();
    session_start();
	if ($_SESSION['userid'] < 1){
    	redirect('login','refresh');
    }

 $this->tinyMce = '
		<!-- TinyMCE -->
		<script type="text/javascript" src="'. base_url().'js/tiny_mce/tiny_mce_gzip.js"></script>
		<script type="text/javascript">
		tinyMCE_GZ.init({
			plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
			
			themes : "simple,advanced",
			languages : "en,el",
			disk_cache : true,
			debug : false
		});
		</script>
		<script type="text/javascript">
		tinyMCE.init({
			// General options
			mode : "textareas",
			plugins : "paste",
			language : "el",
			theme : "advanced",
			paste_remove_styles : "true",
			theme_advanced_blockformats : "p,h1,h2,h3,h4",

			plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

			// Theme options
			theme_advanced_buttons1 : "bold,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect",
			theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,bullist,numlist,|,code",
			theme_advanced_buttons3 : "",
			theme_advanced_buttons4 : "",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "bottom",
			theme_advanced_resizing : true,


				entity_encoding : "raw",
				fix_list_elements : true,
				convert_urls : false,
				relative_urls : false,
				extended_valid_elements : "a[name|href|target|title|onclick|class|params],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]"

		});
		</script>
		<!-- /TinyMCE -->
		';


 
  } 
  function index($path){
  	$data['page'] = $this->MPages->getPageid($path);
	$page_id=$data['page']['id'];
	$data['liID']=$this->uri->segment(4);
	$data['title'] = "Διαχείριση Σελίδας ".$path;
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_home';
	$data['hideColumn']="hideboth";
	$data['page_title'] = $this->MDashboard->getTitle($page_id);
//	$data['page_content'] = $this->MDashboard->getPageContent($id);
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
    function clients($path){
  	$data['page'] = $this->MPages->getPageid($path);
	$page_id=$data['page']['id'];
	$data['liID']=$this->uri->segment(4);
	$data['title'] = "Διαχείριση Σελίδας ".$path;
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_home_clients';
	$data['hideColumn']="hideboth";
	$data['page_title'] = $this->MDashboard->getTitle($page_id);
	$data['clients_titles'] = $this->MDashboard->getAllClientsCategory();
//	$data['page_content'] = $this->MDashboard->getPageContent($id);
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
  function code_memo(){
  	//$data['page'] = $this->MPages->getPageid($path);
	//$page_id=$data['page']['id'];
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Code Memo";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_code';
	$data['hideColumn']="hideboth";
	$data['codes'] = $this->MDashboard->getCodes();
//	$data['page_content'] = $this->MDashboard->getPageContent($id);
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }

  function create(){
   	if ($this->input->post('name')){
  		$this->MDashboard->addPage();
  		$this->session->set_flashdata('message','Η σελίδα δημιουργήθηκε');
  		redirect('admin/pages/index','refresh');
  	}else{
		$data['liID']=$this->uri->segment(4);
		$data['title'] = "Create Page";
		$data['main'] = 'pages_create';
		$data['hideColumn']="hideboth";
		$this->load->vars($data);
		$this->load->view('admin/dashboard_tpl');  
	} 
  }
    function create_section($page_id){
	$data['pid']=$page_id;
		$data['page_path'] = $this->MDashboard->getPagePathPageID($page_id);
	$page_path=$data['page_path']['path'];
//$data['page_id'] = $this->MDashboard->getPageIDSection($section_id);
	//$page_id=$data['page_path']['id'];

   	if ($this->input->post('content')){
  		$this->MDashboard->addContent($page_id);
  		$this->session->set_flashdata('message','Το περιεχόμενο στη σελίδα δημιουργήθηκε');
  		redirect('admin/main/index/'.$page_path,'refresh');
  	}else{
		$data['liID']=$this->uri->segment(4);
		$data['title'] = "Δημιουργία Περιεχομένου στη σελίδα ".$page_path;
		$data['main'] = 'admin/pages_create';
		$data['hideColumn']="hideboth";
		$this->load->vars($data);
		$this->load->view('admin/dashboard_tpl');  
	} 
  }    
  function create_code(){
	if ($this->input->post('name')){
  		$this->MDashboard->addCode();
  		$this->session->set_flashdata('message','Ο Κωδικός δημιουργήθηκε');
  		redirect('admin/main/code_memo','refresh');
  	}else{
		$data['liID']=$this->uri->segment(3);
		$data['title'] = "Δημιουργία Νέου Κωδικού";
		$data['main'] = 'admin/pages_create_code';
		$data['hideColumn']="hideboth";
		$this->load->vars($data);
		$this->load->view('admin/dashboard_tpl');  
	} 
  }

      function create_leftcol($page_id){
	  $data['pid']=$page_id;
  	$data['page_path'] = $this->MDashboard->getPagePathCategory_page_id($page_id);
	$page_path=$data['page_path']['path'];
	//$data['page_id'] = $this->MDashboard->getPageIDSection($section_id);
	//$page_id=$data['page_path']['id'];

   	if ($this->input->post('title')){
  		$this->MDashboard->addLeftcol($page_id);
  		$this->session->set_flashdata('message','Το περιεχόμενο στη σελίδα δημιουργήθηκε');
  		redirect('admin/main/index/'.$page_path,'refresh');
  	}else{
		$data['liID']=$this->uri->segment(4);
		$data['title'] = "Δημιουργία Περιεχομένου στηn αριστερή στήλη της σελίδας ".$page_path;
		$data['main'] = 'admin/pages_create_leftcol';
		$data['hideColumn']="hideboth";
		$this->load->vars($data);
		$this->load->view('admin/dashboard_tpl');  
	} 
  }

  function edit_client($client_id=0){
  	//$data['page_path'] = $this->MDashboard->getPagePath($title_id);
	//$page_path=$data['page_path']['path'];
	$page_path="clients";
  		$data['liID']=$this->uri->segment(4);
		$data['title'] = " Επεξεργασία Πελατών";
		$data['main'] = 'admin/pages_edit_clients';
		$data['hideColumn']="hideboth";
		$data['page'] = $this->MDashboard->getClientsCategory($client_id);
		if (!count($data['page'])){
			redirect('admin/main/index'.$page_path,'refresh');
		}
		$this->load->vars($data);
		$this->load->view('admin/dashboard_tpl');  
	
  }
    function edit_code($code_id=0){
  	//$data['page_path'] = $this->MDashboard->getPagePath($title_id);
	//$page_path=$data['page_path']['path'];
		$data['liID']=$this->uri->segment(4);
		$data['title'] = " Επεξεργασία Κωδικού";
		$data['main'] = 'admin/pages_edit_code';
		$data['hideColumn']="hideboth";
		$data['page'] = $this->MDashboard->getCode($code_id);
		if (!count($data['page'])){
			redirect('admin/main/code_memo','refresh');
		}
		$this->load->vars($data);
		$this->load->view('admin/dashboard_tpl');  
	
  }
  function update_code($code_id=0){
  //$data['page_path'] = $this->MDashboard->getPagePath($title_id);
	//$page_path=$data['page_path']['path'];
  if ($this->input->post('name')){
		$this->MDashboard->updateCode();
  		$this->session->set_flashdata('message','Ο Κωδικός άλλαξε');
  		redirect('admin/main/code_memo','refresh');
  }
  else {
  		$this->MDashboard->updateTitle();
  		$this->session->set_flashdata('message','Πρέπει να εισάσετε τουλάχιστον 1 χαρακτήρα. Το πεδίο δεν μπορεί να είναι κενό!');
  		redirect('admin/main/code_memo','refresh');
}
}

  function edit_leftcol($cat_id=0){
  	$data['page_path'] = $this->MDashboard->getPagePathCategory($cat_id);
	$page_path=$data['page_path']['path'];
		$data['liID']=$this->uri->segment(4);
		$data['title'] = " Επεξεργασία Αριστερής Στήλης στη Σελίδα ".$page_path;
		$data['main'] = 'admin/pages_edit_category';
		$data['hideColumn']="hideboth";
		$data['page'] = $this->MDashboard->getCurrentProject($cat_id);
		if (!count($data['page'])){
			redirect('admin/main/index'.$page_path,'refresh');
		}
		$this->load->vars($data);
		$this->load->view('admin/dashboard_tpl');  
	
  }

  function edit_title($title_id=0){
  	$data['page_path'] = $this->MDashboard->getPagePath($title_id);
	$page_path=$data['page_path']['path'];
	
  		$data['liID']=$this->uri->segment(4);
		$data['title'] = " Επεξεργασία Τίτλου Σελίδας";
		$data['main'] = 'admin/pages_edit';
		$data['hideColumn']="hideboth";
		$data['page'] = $this->MDashboard->getPage_Title($title_id);
		if (!count($data['page'])){
			redirect('admin/main/index'.$page_path,'refresh');
		}
		$this->load->vars($data);
		$this->load->view('admin/dashboard_tpl');  
	
  }
  function update_title($title_id=0){
  $data['page_path'] = $this->MDashboard->getPagePath($title_id);
	$page_path=$data['page_path']['path'];
  if ($this->input->post('title')){
		$this->MDashboard->updateTitle();
  		$this->session->set_flashdata('message','Ο Τίτλος άλλαξε');
  		redirect('admin/main/index/'.$page_path,'refresh');
  }
  else {
  		$this->MDashboard->updateTitle();
  		$this->session->set_flashdata('message','Πρέπει να εισάσετε τουλάχιστον 1 χαρακτήρα. Το πεδίο δεν μπορεί να είναι κενό!');
  		redirect('admin/main/index/'.$page_path,'refresh');
}
}
  function update_leftcol($cat_id=0){
  	$data['page_path'] = $this->MDashboard->getPagePathCategory($cat_id);
	$page_path=$data['page_path']['path'];
  if ($this->input->post('title')){
		$this->MDashboard->updateCategories();
  		$this->session->set_flashdata('message','Η Αριστερή στήλη άλλαξε');
  		redirect('admin/main/index/'.$page_path,'refresh');
  }
  else {
  		$this->MDashboard->updateCategories();
  		$this->session->set_flashdata('message','Πρέπει να εισάσετε τουλάχιστον 1 χαρακτήρα. Το πεδίο δεν μπορεί να είναι κενό!');
  		redirect('admin/main/index/'.$page_path,'refresh');
}

  }
    function update_client($id=0){
  //$data['page_path'] = $this->MDashboard->getPagePath($title_id);
	//$page_path=$data['page_path']['path'];
  if ($this->input->post('title')){
		$this->MDashboard->updateClient();
			$this->session->set_flashdata('message','Οι πελάτες άλλαξαν');
  		redirect('admin/main/clients/clients','refresh');
  }
  else {
  		$this->MDashboard->updateClient();
  		$this->session->set_flashdata('message','Πρέπει να εισάσετε τουλάχιστον 1 χαρακτήρα. Το πεδίο δεν μπορεί να είναι κενό!');
  		redirect('admin/main/clients/clients','refresh');
}
  }

    function edit_section($section_id=0){
	$data['page_path'] = $this->MDashboard->getPagePathSection($section_id);
	$page_path=$data['page_path']['path'];
	
  		$data['liID']=$this->uri->segment(4);
		$data['title'] = "Επεξεργασία Περιεχομένου Σελίδας";
		$data['main'] = 'admin/pages_edit_section';
		$data['hideColumn']="hideboth";
		$data['page'] = $this->MDashboard->getPage_Section($section_id);
		if (!count($data['page'])){
			redirect('admin/main/index'.$page_path,'refresh');
		}
		$this->load->vars($data);
		$this->load->view('admin/dashboard_tpl');  
	
  }
  function update_section($section_id=0){
  $data['page_path'] = $this->MDashboard->getPagePathSection($section_id);
	$page_path=$data['page_path']['path'];
  if ($this->input->post('content')){
		$this->MDashboard->updateSection();
  		$this->session->set_flashdata('message','Ο Τίτλος άλλαξε');
  		redirect('admin/main/index/'.$page_path,'refresh');
  }
  else {
  		$this->MDashboard->updateSection();
  		$this->session->set_flashdata('message','Πρέπει να εισάσετε τουλάχιστον 1 χαρακτήρα. Το πεδίο δεν μπορεί να είναι κενό!');
  		redirect('admin/main/index/'.$page_path,'refresh');
}
  }

  function delete_section($section_id){
    $data['page_path'] = $this->MDashboard->getPagePathSection($section_id);
	$page_path=$data['page_path']['path'];
	//$id = $this->uri->segment(4);
	$this->MDashboard->deleteSection($section_id);
	$this->session->set_flashdata('message','Το πεδίο Διαγράφηκε με επιτυχία.');
	redirect('admin/main/index/'.$page_path,'refresh');
  }
	  function delete_code($code_id){
    $this->MDashboard->deleteCode($code_id);
	$this->session->set_flashdata('message','Το πεδίο Διαγράφηκε με επιτυχία.');
	redirect('admin/main/code_memo','refresh');
  }
  
  function delete_leftcol($cat_id){
  	$data['page_path'] = $this->MDashboard->getPagePathCategory($cat_id);
	$page_path=$data['page_path']['path'];
	//$id = $this->uri->segment(4);
	$this->MDashboard->deleteLeftCol($cat_id);
	$this->session->set_flashdata('message','Το πεδίο Διαγράφηκε με επιτυχία.');
	redirect('admin/main/index/'.$page_path,'refresh');
  }

}//end class
?>
