<?php

class Pages extends Controller {
  
function Pages(){
    parent::Controller();
	session_start();
// 	if ($this->session->userdata('userid') < 1){
//		$this->session->set_flashdata('error',"You've been logged out!");
//		redirect('admin/dashboard/verify','refresh');
//	}
	$uid=$this->session->userdata('adminuserid');

	if ($uid == ''){
    	redirect('admin','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",
			language : "el",
			theme : "advanced",
			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 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
			theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
			theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
			theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
			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(){
	$data['liID']=$this->uri->segment(2);
	$data['title'] = "Διαχείρηση Σελίδων";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_home';
	$data['hideColumn']="hideboth";
	$data['pages'] = $this->MPages->getAllPages();
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
  function page($path){
  
  	$data['page'] = $this->MDashboard->getPageID($path);
	$page_id=$data['page']['id'];
	$page_title=$data['page']['name'];
	$data['liID']=$this->uri->segment(4);
	$data['title'] = 'Διαχείριση Σελίδας "'.$page_title.'"';
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_home';
	$data['page_title'] = $page_title;
	$data['page_id'] = $page_id;
	$data['pages'] = $this->MDashboard->getAllPagesByID($page_id);
//	$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->MPages->addPage();
  		$this->session->set_flashdata('message','Η σελίδα δημιουργήθηκε');
  		redirect('admin/pages/index','refresh');
  	}else{
		$data['liID']=$this->uri->segment(2);
		$data['title'] = "Create Page";
		$data['main'] = 'admin/pages_create';
		$data['hideColumn']="hideboth";
		$this->load->vars($data);
		$this->load->view('admin/dashboard_tpl');  
	} 
  }
  
  function edit($id=0){
   	$data['page'] = $this->MDashboard->getPagePath($id);
	$page_path=$data['page']['path'];
	$page_title=$data['page']['name'];
  	if ($this->input->post('name')){
  		$this->MDashboard->updatePage($id);
  		$this->session->set_flashdata('message','Η σελίδα άλλαξε');
  		redirect('admin/pages/page/'.$page_path,'refresh');
  	}else{
		$data['liID']=$this->uri->segment(4);
		$data['page_id'] = $id;
		$data['title'] = 'Επεξεργασία σελίδας "'.$page_title.'"';
		$data['main'] = 'admin/pages_edit';
		$data['hideColumn']="hideboth";
		$data['page'] = $this->MDashboard->getPage($id);
		if (!count($data['page'])){
			redirect('admin/pages/page/'.$page_path,'refresh');
		}
		$this->load->vars($data);
		$this->load->view('admin/dashboard_tpl');  
	}
  }
  
  function delete($id){
	//$id = $this->uri->segment(4);
	$this->MPages->deletePage($id);
	$this->session->set_flashdata('message','Page deleted');
	redirect('admin/pages/index','refresh');
  }
	
}//end class
?>