<?php

class Categories extends Controller {
  
  function Categories(){
    parent::Controller();
    session_start();
	$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,de",
			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,|,image,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 : true,
				relative_urls : true,
				document_base_url :"http://www.wines2u.gr/",
				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 top(){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Κειμένων Site 'Header'";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_top';
	$data['content'] = $this->MAdmins->getPagesbySection('top');
	$data['edit_id']='';
	$data['edit']=false;
	$data['add']=false;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
function edit_top($id){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Κειμένου 'Header'";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_top';
	$data['hideColumn']="hideboth";
	$data['content'] = $this->MAdmins->getPagesbySection('top');
	$data['edit_content'] = $this->MAdmins->getPagebyID($id);
	$data['edit_id'] = $id;
	$data['edit']=true;
	$data['add']=false;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
function update_top($id){
  if ($this->input->post('name')){
		$this->MAdmins->updatePageTop($id);
  		$this->session->set_flashdata('message','ΟΙ αλλαγές αποθηκεύτηκαν');
  		redirect('admin/categories/top','refresh');
  }
  else {
  		$this->session->set_flashdata('message','Δεν έχετε συμπληρώσει όλα τα πεδία!');
  		redirect('admin/categories/edit_top/'.$id, 'refresh');
	}
	}
function add_top(){
	if (($this->input->post('name1')) && ($this->input->post('name2'))){
		$this->MAdmins->addPagebySectionTop('top');
  		$this->session->set_flashdata('message','Η νέα εγγραφή καταχωρήθηκε');
  		redirect('admin/categories/top','refresh');
    } else {
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Κειμένων 'Header'";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_top';
	$data['hideColumn']="hideboth";
	$data['content'] = $this->MAdmins->getPagesbySection('top');
	$data['edit_id'] = '';
	$data['edit']=false;
	$data['add']=true;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
	}
  }
function delete_page_top($id){
		$this->MAdmins->deletePage($id);
  		$this->session->set_flashdata('message','Η εγγραφή διαγράφηκε');
  		redirect('admin/categories/top','refresh');
	}
function home_page(){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Κειμένων Site";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_home';
	$data['content'] = $this->MAdmins->getPages();
	$data['edit_id']='';
	$data['edit']=false;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
  
  function edit_home_page($id){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση link About Us";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_home';
	$data['hideColumn']="hideboth";
	$data['content'] = $this->MAdmins->getPages();
	$data['edit_content'] = $this->MAdmins->getPagebyID($id);
	$data['edit_id'] = $id;
	$data['edit']=true;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
  function update_home_page($id){
  if (($this->input->post('title')) && ($this->input->post('content'))){
		$this->MAdmins->updatePage($id);
  		$this->session->set_flashdata('message','ΟΙ αλλαγές αποθηκεύτηκαν');
  		redirect('admin/categories/home_page','refresh');
  }
  else {
  		$this->session->set_flashdata('message','Δεν έχετε συμπληρώσει όλα τα πεδία!');
  		redirect('admin/categories/edit_home_page/'.$id, 'refresh');
	}
	}
  function bottom_right(){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Κειμένων Site 'Περί Κρασιού'";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_bottom_right';
	$data['content'] = $this->MAdmins->getPagesbySection('bottom_right');
	$data['edit_id']='';
	$data['edit']=false;
	$data['add']=false;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
  
  function edit_bottom_right($id){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Κειμένου 'Περί Κρασιού'";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_bottom_right';
	$data['hideColumn']="hideboth";
	$data['content'] = $this->MAdmins->getPagesbySection('bottom_right');
	$data['edit_content'] = $this->MAdmins->getPagebyID($id);
	$data['edit_id'] = $id;
	$data['edit']=true;
	$data['add']=false;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
  function update_bottom_right($id){
  if (($this->input->post('title')) && ($this->input->post('content'))){
		$this->MAdmins->updatePage($id);
  		$this->session->set_flashdata('message','ΟΙ αλλαγές αποθηκεύτηκαν');
  		redirect('admin/categories/bottom_right','refresh');
  }
  else {
  		$this->session->set_flashdata('message','Δεν έχετε συμπληρώσει όλα τα πεδία!');
  		redirect('admin/categories/edit_bottom_right/'.$id, 'refresh');
	}
	}
function add_bottom_right(){
	if (($this->input->post('name1')) && ($this->input->post('name2'))){
		$this->MAdmins->addPagebySection('bottom_right');
  		$this->session->set_flashdata('message','Η νέα εγγραφή καταχωρήθηκε');
  		redirect('admin/categories/bottom_right','refresh');
    } else {
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Κειμένων 'Περί Κρασιού'";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_bottom_right';
	$data['hideColumn']="hideboth";
	$data['content'] = $this->MAdmins->getPagesbySection('bottom_right');
	$data['edit_id'] = '';
	$data['edit']=false;
	$data['add']=true;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
	}
  }
  function bottom(){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Κειμένων Site 'Footer'";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_bottom';
	$data['content'] = $this->MAdmins->getPagesbySection('bottom');
	$data['edit_id']='';
	$data['edit']=false;
	$data['add']=false;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
  
  function edit_bottom($id){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Κειμένου 'Footer'";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_bottom';
	$data['hideColumn']="hideboth";
	$data['content'] = $this->MAdmins->getPagesbySection('bottom');
	$data['edit_content'] = $this->MAdmins->getPagebyID($id);
	$data['edit_id'] = $id;
	$data['edit']=true;
	$data['add']=false;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
  function update_bottom($id){
  if (($this->input->post('title')) && ($this->input->post('content'))){
		$this->MAdmins->updatePage($id);
  		$this->session->set_flashdata('message','ΟΙ αλλαγές αποθηκεύτηκαν');
  		redirect('admin/categories/bottom','refresh');
  }
  else {
  		$this->session->set_flashdata('message','Δεν έχετε συμπληρώσει όλα τα πεδία!');
  		redirect('admin/categories/edit_bottom/'.$id, 'refresh');
	}
	}
function add_bottom(){
	if (($this->input->post('name1')) && ($this->input->post('name2'))){
		$this->MAdmins->addPagebySection('bottom');
  		$this->session->set_flashdata('message','Η νέα εγγραφή καταχωρήθηκε');
  		redirect('admin/categories/bottom','refresh');
    } else {
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Κειμένων 'Footer'";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_bottom';
	$data['hideColumn']="hideboth";
	$data['content'] = $this->MAdmins->getPagesbySection('bottom');
	$data['edit_id'] = '';
	$data['edit']=false;
	$data['add']=true;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
	}
  }
  function delete_page_bottom($id){
		$this->MAdmins->deletePage($id);
  		$this->session->set_flashdata('message','Η εγγραφή διαγράφηκε');
  		redirect('admin/categories/bottom','refresh');
	}
  function delete_page($id){
		$this->MAdmins->deletePage($id);
  		$this->session->set_flashdata('message','Η εγγραφή διαγράφηκε');
  		redirect('admin/categories/bottom_right','refresh');
	}
function right_cat(){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Κατηγοριών 'Οινοτουρισμού'";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_right_cat';
	$data['categories'] = $this->MAdmins->getRightCategories();
	$data['edit_cat']=false;
	$data['add_cat']=false;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
function add_right_cat(){
	if (($this->input->post('name1')) && ($this->input->post('name2'))){
		$this->MAdmins->addRightCategory();
  		$this->session->set_flashdata('message','Η νέα εγγραφή καταχωρήθηκε');
  		redirect('admin/categories/right_cat','refresh');
    } else {
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Κατηγοριών 'Οινοτουρισμού'";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_right_cat';
	$data['categories'] = $this->MAdmins->getRightCategories();
	$data['edit_cat']=false;
	$data['add_cat']=true;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
	}
  }
  function update_right_cat($id, $cat_id){
  if (($this->input->post('name1')) && ($this->input->post('name2'))){
		$this->MAdmins->updateRightCategory($id, $cat_id);
  		$this->session->set_flashdata('message','ΟΙ αλλαγές αποθηκεύτηκαν');
  		redirect('admin/categories/right_cat','refresh');
  }
  else {
  		$this->session->set_flashdata('message','Δεν έχετε συμπληρώσει όλα τα πεδία!');
  		redirect('admin/categories/edit_right_cat/'.$id, 'refresh');
	}
	}
function delete_right_cat($id){
		$this->MAdmins->deleteRightCategory($id);
  		$this->session->set_flashdata('message','Η εγγραφή διαγράφηκε');
  		redirect('admin/categories/right_cat','refresh');
	}
function edit_right_cat($id){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Κατηγοριών 'Οινοτουρισμού'";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_right_cat';
	$data['categories'] = $this->MAdmins->getRightCategories();
	$data['edit_cat']=true;
	$data['add_cat']=false;
	$data['edit_id'] = $id;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }

function settings(){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Ρυθμίσεων";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_settings';
	$data['categories'] = $this->MAdmins->getCategories();
	$data['news'] = $this->MAdmins->getNews();
	$data['edit_cat']=false;
	$data['add_cat']=false;
	$data['edit_new']=false;
	$data['add_new']=false;
	$data['edit_key']=false;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
  function edit_keywords($id){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Ρυθμίσεων";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_settings';
	$data['categories'] = $this->MAdmins->getCategories();
	$data['edit_cat']=false;
	$data['add_cat']=false;
	$data['edit_new']=false;
	$data['add_new']=false;
	$data['edit_key']=true;
	$data['edit_id'] ='';
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
    function update_keywords($id){
  if ($this->input->post('keywords')) {
		$this->MAdmins->updateKeywords($id);
  		$this->session->set_flashdata('message','ΟΙ αλλαγές αποθηκεύτηκαν');
  		redirect('admin/categories/settings','refresh');
  }
  else {
  		$this->session->set_flashdata('message','Δεν έχετε συμπληρώσει όλα τα πεδία!');
  		redirect('admin/categories/edit_keywords/'.$id, 'refresh');
	}
	}
function add_category(){
	if (($this->input->post('name1')) && ($this->input->post('name2'))){
		$this->MAdmins->addCategory();
  		$this->session->set_flashdata('message','Η νέα εγγραφή καταχωρήθηκε');
  		redirect('admin/categories/settings','refresh');
    } else {
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Ρυθμίσεων";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_settings';
	$data['categories'] = $this->MAdmins->getCategories();
	$data['news'] = $this->MAdmins->getNews();
	$data['edit_cat']=false;
	$data['add_cat']=true;
	$data['edit_new']=false;
	$data['add_new']=false;
	$data['edit_key']=false;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
	}
  }
function add_new(){
	if (($this->input->post('title1')) && ($this->input->post('title2'))){
		$this->MAdmins->addNew();
  		$this->session->set_flashdata('message','Η νέα εγγραφή καταχωρήθηκε');
  		redirect('admin/categories/settings','refresh');
    } else {
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Ρυθμίσεων";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_settings';
	$data['categories'] = $this->MAdmins->getCategories();
	$data['news'] = $this->MAdmins->getNews();
	$data['edit_cat']=false;
	$data['add_cat']=false;
	$data['edit_new']=false;
	$data['add_new']=true;
	$data['edit_key']=false;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
	}
  }
    function edit_category($id){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Ρυθμίσεων";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_settings';
	$data['categories'] = $this->MAdmins->getCategories();
	$data['news'] = $this->MAdmins->getNews();
	$data['edit_cat']=true;
	$data['add_cat']=false;
	$data['edit_id'] = $id;
	$data['edit_new']=false;
	$data['add_new']=false;
	$data['edit_key']=false;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
    function edit_new($id){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Ρυθμίσεων";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_settings';
	$data['categories'] = $this->MAdmins->getCategories();
	$data['news'] = $this->MAdmins->getNews();
	$data['edit_cat']=false;
	$data['add_cat']=false;
	$data['edit_id'] = $id;
	$data['edit_new']=true;
	$data['add_new']=false;
	$data['edit_key']=false;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }

  function update_category($id, $cat_id){
  if (($this->input->post('name1')) && ($this->input->post('name2'))){
		$this->MAdmins->updateCategory($id, $cat_id);
  		$this->session->set_flashdata('message','ΟΙ αλλαγές αποθηκεύτηκαν');
  		redirect('admin/categories/settings','refresh');
  }
  else {
  		$this->session->set_flashdata('message','Δεν έχετε συμπληρώσει όλα τα πεδία!');
  		redirect('admin/categories/edit_category/'.$id, 'refresh');
	}
	}
  function delete_category($id){
		$this->MAdmins->deleteCategory($id);
  		$this->session->set_flashdata('message','Η εγγραφή διαγράφηκε');
  		redirect('admin/categories/settings','refresh');
	}
  function update_new($id, $new_id){
  if (($this->input->post('title1')) && ($this->input->post('title2'))){
		$this->MAdmins->updateNew($id, $new_id);
  		$this->session->set_flashdata('message','ΟΙ αλλαγές αποθηκεύτηκαν');
  		redirect('admin/categories/settings','refresh');
  }
  else {
  		$this->session->set_flashdata('message','Δεν έχετε συμπληρώσει όλα τα πεδία!');
  		redirect('admin/categories/edit_new/'.$id, 'refresh');
	}
	}
  function delete_new($id){
		$this->MAdmins->deleteNew($id);
  		$this->session->set_flashdata('message','Η εγγραφή διαγράφηκε');
  		redirect('admin/categories/settings','refresh');
	}
 function view_category($cat_id){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Κατηγοριών";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_sub_category';
	$data['category'] = $this->MAdmins->getCategoryName($cat_id, 1);
	$data['subcategories'] = $this->MAdmins->getSubCategories($cat_id);
	$data['edit_subcat']=false;
	$data['add_subcat']=false;
	$data['edit_id'] = '';
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }

  function add_subcategory($id){
	if ($this->input->post('name1')){
		$this->MAdmins->addSubCategory($id);
  		$this->session->set_flashdata('message','Η νέα εγγραφή καταχωρήθηκε');
  		redirect('admin/categories/view_category/'.$id,'refresh');
	//} elseif (($this->input->post('name')=='') && ($this->input->post('language')=='')){
		//$this->session->set_flashdata('message','Δεν έχετε συμπληρώσει όλα τα πεδία!');
  		//redirect('admin/categories/add_location','');
    } else {
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Κατηγοριών";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_sub_category';
	$data['languages'] = $this->MAdmins->getLanguages();
	$data['category'] = $this->MAdmins->getCategory($id);
	$data['subcategories'] = $this->MAdmins->getSubCategories($id);
	$data['edit_subcat']=false;
	$data['add_subcat']=true;
	$data['edit_id'] = '';
//	$data['page_content'] = $this->MDashboard->getPageContent($id);
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
	}
  }
   function delete_subcategory($id, $s_id){
		$this->MAdmins->deleteSubCategory($s_id);
  		$this->session->set_flashdata('message','Η εγγραφή διαγράφηκε');
  		redirect('admin/categories/view_category/'.$id,'refresh');
	}
   function edit_subcategory($id, $s_id){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Κατηγοριών";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_sub_category';
	$data['category'] = $this->MAdmins->getCategory($id);
	$data['subcategories'] = $this->MAdmins->getSubCategories($id);
	$data['edit_subcat']=true;
	$data['add_subcat']=false;
	$data['edit_id'] = $s_id;
//	$data['page_content'] = $this->MDashboard->getPageContent($id);
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
  function update_subcategory($id, $s_id){
  if ($this->input->post('name1')){
		$this->MAdmins->updateSubCategory($s_id);
  		$this->session->set_flashdata('message','Οι αλλαγές αποθηκεύτηκαν');
  		redirect('admin/categories/view_category/'.$id,'refresh');
  }
  else {
  		$this->session->set_flashdata('message','Δεν έχετε συμπληρώσει όλα τα πεδία!');
  		redirect('admin/categories/edit_subcategory/'.$id.'/'.$s_id, 'refresh');
	}
	}


 function view_sub_category($sub_id){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Κατηγοριών";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_sub_sub_category';
	$data['subcategory'] = $this->MAdmins->getSubCategoryName($sub_id, 1);
	$data['category'] = $this->MAdmins->getCategoryName($data['subcategory']['cat_id'], 1);
	$data['subsubcategories'] = $this->MAdmins->getSubSubCategories($sub_id);
	$data['edit_subcat']=false;
	$data['add_subcat']=false;
	$data['edit_id'] = '';
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }

  function add_subsubcategory($id, $cat_id){
	if ($this->input->post('name1')){
		$this->MAdmins->addSubSubCategory($id, $cat_id);
  		$this->session->set_flashdata('message','Η νέα εγγραφή καταχωρήθηκε');
  		redirect('admin/categories/view_sub_category/'.$id,'refresh');
	//} elseif (($this->input->post('name')=='') && ($this->input->post('language')=='')){
		//$this->session->set_flashdata('message','Δεν έχετε συμπληρώσει όλα τα πεδία!');
  		//redirect('admin/categories/add_location','');
    } else {
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Κατηγοριών";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_sub_sub_category';
	$data['languages'] = $this->MAdmins->getLanguages();
	$data['subcategory'] = $this->MAdmins->getSubCategoryName($id, 1);
	$data['category'] = $this->MAdmins->getCategoryName($data['subcategory']['cat_id'], 1);
	$data['subsubcategories'] = $this->MAdmins->getSubSubCategories($id);
	$data['edit_subcat']=false;
	$data['add_subcat']=true;
	$data['edit_id'] = '';
//	$data['page_content'] = $this->MDashboard->getPageContent($id);
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
	}
  }
   function delete_subsubcategory($id, $s_id){
		$this->MAdmins->deleteSubSubCategory($s_id);
  		$this->session->set_flashdata('message','Η εγγραφή διαγράφηκε');
  		redirect('admin/categories/view_sub_category/'.$id,'refresh');
	}
   function edit_subsubcategory($id, $s_id){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Κατηγοριών";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_sub_sub_category';
	$data['subcategory'] = $this->MAdmins->getSubCategoryName($id, 1);
	$data['category'] = $this->MAdmins->getCategoryName($data['subcategory']['cat_id'], 1);
	$data['subsubcategories'] = $this->MAdmins->getSubSubCategories($id);
	$data['edit_subcat']=true;
	$data['add_subcat']=false;
	$data['edit_id'] = $s_id;
//	$data['page_content'] = $this->MDashboard->getPageContent($id);
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
  function update_subsubcategory($id, $s_id){
  if ($this->input->post('name1')){
		$this->MAdmins->updateSubSubCategory($s_id);
  		$this->session->set_flashdata('message','Οι αλλαγές αποθηκεύτηκαν');
  		redirect('admin/categories/view_sub_category/'.$id,'refresh');
  }
  else {
  		$this->session->set_flashdata('message','Δεν έχετε συμπληρώσει όλα τα πεδία!');
  		redirect('admin/categories/edit_subsubcategory/'.$id.'/'.$s_id, 'refresh');
	}
	}

function varieties(){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Ποικιλίες";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_varieties';
	$data['varieties'] = $this->MAdmins->getVarieties();
	$data['edit_var']=false;
	$data['add_var']=false;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
function add_variety(){
	if (($this->input->post('name1')) && ($this->input->post('name2'))){
		$this->MAdmins->addVariety();
  		$this->session->set_flashdata('message','Η νέα εγγραφή καταχωρήθηκε');
  		redirect('admin/categories/varieties','refresh');
    } else {
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Ποικιλίες";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_varieties';
	$data['varieties'] = $this->MAdmins->getVarieties();
	$data['edit_var']=false;
	$data['add_var']=true;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
	}
  }
    function edit_variety($id){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Ποικιλίες";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_varieties';
	$data['varieties'] = $this->MAdmins->getVarieties();
	$data['edit_var']=true;
	$data['add_var']=false;
	$data['edit_id'] = $id;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
  function update_variety($id, $var_id){
  if (($this->input->post('name1')) && ($this->input->post('name2'))){
		$this->MAdmins->updateVariety($id, $var_id);
  		$this->session->set_flashdata('message','ΟΙ αλλαγές αποθηκεύτηκαν');
  		redirect('admin/categories/varieties','refresh');
  }
  else {
  		$this->session->set_flashdata('message','Δεν έχετε συμπληρώσει όλα τα πεδία!');
  		redirect('admin/categories/edit_variety/'.$id, 'refresh');
	}
	}
  function delete_variety($id){
		$this->MAdmins->deleteVariety($id);
  		$this->session->set_flashdata('message','Η εγγραφή διαγράφηκε');
  		redirect('admin/categories/varieties','refresh');
	}


 function view_right_category($cat_id){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Κατηγοριών - Κείμενα";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_right_sub_cat';
	$data['category'] = $this->MAdmins->getRightCategoryName($cat_id, 1);
	$data['subcategories'] = $this->MAdmins->getRightSubCategories($cat_id);
	$data['edit_subcat']=false;
	$data['add_subcat']=false;
	$data['edit_id'] = '';
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }

  function add_right_category($id){
	if ($this->input->post('name1')){
		$this->MAdmins->addRightSubCategory($id);
  		$this->session->set_flashdata('message','Η νέα εγγραφή καταχωρήθηκε');
  		redirect('admin/categories/view_right_category/'.$id,'refresh');
	//} elseif (($this->input->post('name')=='') && ($this->input->post('language')=='')){
		//$this->session->set_flashdata('message','Δεν έχετε συμπληρώσει όλα τα πεδία!');
  		//redirect('admin/categories/add_location','');
    } else {
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Κατηγοριών - Κείμενα";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_right_sub_cat';
	$data['languages'] = $this->MAdmins->getLanguages();
	$data['category'] = $this->MAdmins->getRightCategoryName($id, 1);
	$data['subcategories'] = $this->MAdmins->getRightSubCategories($id);
	$data['edit_subcat']=false;
	$data['add_subcat']=true;
	$data['edit_id'] = '';
//	$data['page_content'] = $this->MDashboard->getPageContent($id);
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
	}
  }
   function delete_right_category($id, $s_id){
		$this->MAdmins->deleteRightSubCategory($s_id);
  		$this->session->set_flashdata('message','Η εγγραφή διαγράφηκε');
  		redirect('admin/categories/view_right_category/'.$id,'refresh');
	}
   function edit_right_category($id, $s_id){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Κατηγοριών - Κείμενα";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_right_sub_cat';
	$data['category'] = $this->MAdmins->getRightCategoryName($id, 1);
	$data['subcategories'] = $this->MAdmins->getRightSubCategories($id);
	$data['edit_subcat']=true;
	$data['add_subcat']=false;
	$data['edit_id'] = $s_id;
//	$data['page_content'] = $this->MDashboard->getPageContent($id);
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
  function update_right_category($id, $s_id){
  if ($this->input->post('name1')){
		$this->MAdmins->updateRightSubCategory($s_id);
  		$this->session->set_flashdata('message','Οι αλλαγές αποθηκεύτηκαν');
  		redirect('admin/categories/view_right_category/'.$id,'refresh');
  }
  else {
  		$this->session->set_flashdata('message','Δεν έχετε συμπληρώσει όλα τα πεδία!');
  		redirect('admin/categories/edit_right_category/'.$id.'/'.$s_id, 'refresh');
	}
	}
   function orders(){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση παραγγελιών";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_orders';
	$data['orders'] = $this->MAdmins->getOrders();
//	$data['page_content'] = $this->MDashboard->getPageContent($id);
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
   function paypal_orders(){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση παραγγελιών μέσω PayPal";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_orders';
	$data['orders'] = $this->MAdmins->getPayPalOrders();
//	$data['page_content'] = $this->MDashboard->getPageContent($id);
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
   function view_order($order_id){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Προβολή Παραγγελίας";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_view_order';
	$data['order'] = $this->MAdmins->getOrder($order_id);
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }  
   function update_sent($status, $order_id){
		$this->MAdmins->updateOrderSent($order_id, $status);
  		$this->session->set_flashdata('message','Οι αλλαγές αποθηκεύτηκαν');
  		redirect('admin/categories/view_order/'.$order_id,'refresh');
  }  
   function update_payed($status, $order_id){
		$this->MAdmins->updateOrderPayed($order_id, $status);
  		$this->session->set_flashdata('message','Οι αλλαγές αποθηκεύτηκαν');
  		redirect('admin/categories/view_order/'.$order_id,'refresh');
  }  
   function delete_order($order_id){
		$this->MAdmins->deleteOrder($order_id);
  		$this->session->set_flashdata('message','Η παραγγελία διεγράφη');
  		redirect('admin/categories/orders','refresh');
  }  
function complete_order($orderid){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		//$order_id=$this->session->userdata('orderid');
		$order_id=$orderid;
		$id=$this->session->userdata('userid');
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $orderid);

 if ($data['orderdata']) { 
 $cart = "<table class='full' width='100%' border='0'>";
 $cart .= "<tr>";
 $cart .= "<th>QTY</th>";
 $cart .= "<th>Item Description</th>";
 $cart .= "<th>Item Price</th>";
 $cart .= "<th>Sub-Total</th>";
 $cart .= "</tr>";

		$order_details = $this->MFuncs->GetOrderDetails($data['orderdata']['id']);
		if ($order_details) {
		$total = 0;
		
		$weight = 0;
		$bot_num = 0;
		$pack_total = 0;
		$ship_total = 0;

    	foreach($order_details as $result=>$order_det):
        $product_details = $this->MFuncs->getProductDetails($order_det['product_id']);
		$product_category = $this->MFuncs->getProductCat($order_det['product_id']);

		$product_category_name = $this->MFuncs->getCategory($product_category['cat_id']);
		$product_sub_category = $this->MFuncs->getProductSubCat($order_det['product_id']);
  		if ($product_sub_category) {
		$product_sub_category_name = $this->MFuncs->getSubCategory($product_sub_category['subcat_id']);
		}
		
 $cart .= "<tr>";
 $cart .= "<td>".$order_det['quantity']."</td>";
  if ($product_sub_category) {
 $cart .= "<td>".$product_category_name['cat_name']."-".$product_sub_category_name['name']."-".$product_details['name']."</td>";
 } else {
 $cart .= "<td>".$product_category_name['cat_name']."-".$product_details['name']."</td>";
 }
 $cart .= "<td>".number_format($order_det['price'], 2, '.', '')."</td>";
 $cart .= "<td>&euro; ".number_format($order_det['price']*$order_det['quantity'], 2, '.', '')."</td>";
 $total = $total + $order_det['price']*$order_det['quantity'];
 $weight = $weight + ($product_details['weight'] * $order_det['quantity']);
 if ($product_category['cat_id']!='7') { 
          $bot_num = $bot_num + $order_det['quantity']; 
		  }
 $cart .= "</tr>";
    	endforeach;
$pay_on_arrival_cost=0;
$can_ship=true;
 $cart .= "<tr>";
 $cart .= "<td colspan='2'> </td>";
 $cart .= "<td><strong>Total</strong></td>";
 $cart .= "<td>&euro; ".number_format($total, 2, '.', '')."</td>";
 $cart .= "</tr>";
       if ($data['orderdata']['same_address']=='No') { 
 			$c_id = $data['orderdata']['country_id']; 
        } elseif ($data['orderdata']['same_address']=='Yes') {
            $c_id = $data['userdata']['country_id'];
        }
        if ($c_id!='1') { 
        if ($data['orderdata']['ship_method']=='courier_economy') { 
	   		$rounded_weight = ceil($weight/1000);
			$insurance_cost = $rounded_weight*0.05;
			if ($insurance_cost>10) { $insurance_cost=10; }
			$country_zone = $this->MFuncs->getCountryZone($c_id);
			$value = $this->MFuncs->getTNT_Cost_economy($rounded_weight, $country_zone['tnt_zones']);
			$ship_total = ($value['price']*0.205) + $value['price'];
			//if (($country_zone['zones']=='F') || ($country_zone['zones']=='FCY') || ($country_zone['zones']=='M')) {
			$ship_total = ($ship_total*0.23) + $ship_total;
			//}
			$ship_total = $insurance_cost + $ship_total;
			$ship_total = number_format($ship_total, 2, '.', '');
        } elseif ($data['orderdata']['ship_method']=='courier_express') { 
	   		$rounded_weight = ceil($weight/1000);
			$insurance_cost = $rounded_weight*0.05;
			if ($insurance_cost>10) { $insurance_cost=10; }
			$country_zone = $this->MFuncs->getCountryZone($c_id);
			if ($rounded_weight<=30) {
			$value = $this->MFuncs->getTNT_Cost_express($rounded_weight, $country_zone['tnt_zones_express']);
			$total_ship_cost = $value['price'];
			} else {
			$value = $this->MFuncs->getTNT_Cost_express(30, $country_zone['tnt_zones_express']);
			$extra_cost_pk = $this->MFuncs->getTNT_extra_Cost($country_zone['tnt_zones_express']);
			$extra_ship_cost = (($rounded_weight-30) * $extra_cost_pk['price']);
			$total_ship_cost = $extra_ship_cost + $value['price'];
			}
			$ship_total = ($total_ship_cost*0.205) + $total_ship_cost;
			//if (($country_zone['zones']=='F') || ($country_zone['zones']=='FCY') || ($country_zone['zones']=='M')) {
			$ship_total = ($ship_total*0.23) + $ship_total;
			//}
			$ship_total = $insurance_cost + $ship_total;
			$ship_total = number_format($ship_total, 2, '.', '');
         }
            $cart .= "<tr>";
            $cart .= "<td colspan='2'></td>";
            $cart .= "<td><strong>Shippment cost</strong></td>";
            $cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
            $cart .= "</tr>";
			$cart .= "<tr>";
			$cart .= "<td colspan='2'></td>";
			$cart .= "<td><strong>Total</strong></td>";
			$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
			$cart .= "</tr>";


         } else { 

 if (($data['orderdata']['ship_method']=='courier') || ($data['orderdata']['ship_method']=='elta')) {
$pack_total = (ceil($bot_num/2))*0.53;
           if ($data['orderdata']['ship_dest']=='attica-center') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(0, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(2.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(4.96, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-suberbs') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(3.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(6.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(9.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-suberbs-out') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(5.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(9.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(13.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-rest') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(2.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(4.96, 2, '.', '');
			   } else {
			   $ship_total = number_format(6.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-peir') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(3.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(6.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(9.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-peir-out') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(5.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(9.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(13.90, 2, '.', '');
			   }

		   } elseif ($data['orderdata']['ship_dest']=='attica') { 
             $i = ceil($weight/1000);
			 if ($data['orderdata']['ship_method']=='courier') {
             if ($i>35) { 
             $can_ship=false;
             } else { 
             $can_ship=true; 
             } 
             $value_ship = $this->MFuncs->getCourierCost($i, 'courier_attica_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } elseif ($data['orderdata']['ship_method']=='elta') { 
             if ($i>20) { 
             $value_ship = $this->MFuncs->getCourierCost(20, 'elta_attica_cost');
			 $remaining_weight = $i - 20; 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'] + ($remaining_weight*0.60), 2, '.', '');
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } else { 
             $value_ship = $this->MFuncs->getCourierCost($i, 'elta_attica_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 

             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } 
            
             } 
	   
		   } elseif ($data['orderdata']['ship_dest']=='greece') { 
             $i = ceil($weight/1000); 
			 if ($data['orderdata']['ship_method']=='courier') { 
             if ($i>35) { 
             $can_ship=false; 
             } else { 
             $can_ship=true; 
             } 
             $value_ship = $this->MFuncs->getCourierCost($i, 'courier_greece_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } elseif ($data['orderdata']['ship_method']=='elta') { 
             if ($i>20) { 
             $value_ship = $this->MFuncs->getCourierCost(20, 'elta_greece_cost');
			 $remaining_weight = $i - 20; 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'] + ($remaining_weight*0.60), 2, '.', '');
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } else {
             $value_ship = $this->MFuncs->getCourierCost($i, 'elta_greece_cost');
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', '');
			 } else {
             $ship_total = number_format(0, 2, '.', '');
             } 
             } 
            
             } 
 		   } elseif ($data['orderdata']['ship_dest']=='crete') { 
             $i = ceil($weight/1000);
			 if ($data['orderdata']['ship_method']=='courier') { 
             if ($i>35) { 
             $can_ship=false; 
             } else { 
             $can_ship=true; 
             } 
             $value_ship = $this->MFuncs->getCourierCost($i, 'courier_crete_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } elseif ($data['orderdata']['ship_method']=='elta') { 
             if ($i>20) { 
             $value_ship = $this->MFuncs->getCourierCost(20, 'elta_crete_cost'); 
			 $remaining_weight = $i - 20; 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'] + ($remaining_weight*0.60), 2, '.', '');
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } else { 
             $value_ship = $this->MFuncs->getCourierCost($i, 'elta_crete_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } 
            
             } 
         
          
           } 
        if ($can_ship==false) {
$cart .= "<tr>";
$cart .= "<td colspan='1'></td>";
$cart .= "<td colspan='3'><strong>Your products cannot be shipped via courier, please select the post office</strong></td>";
$cart .= "</tr>";
        $ship_total=0;
          } else {
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>Shippment cost</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
         } 
 if (($data['orderdata']['ship_dest']=='attica') || ($data['orderdata']['ship_dest']=='greece') || ($data['orderdata']['ship_dest']=='crete')) {
	  if ($data['orderdata']['pay_method']=='Cash') {
		  if ($data['orderdata']['ship_method']=='elta') {
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>Pay cash on delivery cost</strong></td>";
$pay_on_arrival_cost = number_format(2.30, 2, '.', '');
$cart .= "<td>&euro; ".number_format($pay_on_arrival_cost, 2, '.', '')."</td>";
$cart .= "</tr>";
         } elseif ($data['orderdata']['ship_method']=='courier') {
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>Pay cash on delivery cost</strong></td>";
$pay_on_arrival_cost = number_format(5.17, 2, '.', '');
$cart .= "<td>&euro; ".number_format($pay_on_arrival_cost, 2, '.', '')."</td>";
$cart .= "</tr>";
          } 
      }        
  }
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>Total</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total + $pay_on_arrival_cost."</td>";
$cart .= "</tr>";

} elseif ($data['orderdata']['ship_method']=='day_delivery') {
        		$ship_total = number_format(14.76, 2, '.', '');
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>Shippment cost</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>Total</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
$cart .= "</tr>";

		 }
	   }
	}
 $cart .= "</table>";
 $cart .= "<Br>";
 $cart .= "<em>In all above prices VAT is included</em>";
 if (($data['orderdata']['ship_method']=='courier') || ($data['orderdata']['ship_method']=='day_delivery') || ($data['orderdata']['ship_method']=='elta') || ($data['orderdata']['ship_method']=='courier_economy') || ($data['orderdata']['ship_method']=='courier_express')) {
if ($data['orderdata']['ship_method']=='courier_economy') {
 $cart .= "<h4>Shipping Method</h4>";
 $cart .= "<h4>Shipment via courier economy (5-6 business days)</h4>";
 } elseif ($data['orderdata']['ship_method']=='courier_express') {
 $cart .= "<h4>Shipping Method</h4>";
 $cart .= "<h4>Shipment via courier express (1-2 business days)</h4>";
 } elseif ($data['orderdata']['ship_method']=='courier') {
 $cart .= "<h4>Shipping Method</h4>";
 $cart .= "<h4>Shipment within 2 days via courier</h4>";
} elseif ($data['orderdata']['ship_method']=='elta') {
 $cart .= "<h4>Shipping Method</h4>";
 $cart .= "<h4>Shipment within 5 days via greek post office</h4>";
 } else {
 $cart .= "<h4>Shipping Method</h4>";
 $cart .= "<h4>Shipment within day only in Attica</h4>";
 }
 $cart .= "<h4>Please select the delivery address</h4>";
 if ($data['orderdata']['same_address']=='Yes') {
 $country_zone = $this->MFuncs->getCountryZone($data['userdata']['country_id']);
 $cart .= "<h4>".$data['userdata']['address'].", ".$data['userdata']['city'].", ".$data['userdata']['postal'].", ".$country_zone['name']."<br>Floor: ".$data['userdata']['floor'].", Name on the bell: ".$data['userdata']['name_bell']."<br>Telephone: ".$data['userdata']['tel'].", Mobile: ".$data['userdata']['mob']."</h4>";
 }else { 
 $country_zone = $this->MFuncs->getCountryZone($data['orderdata']['country_id']);
 $cart .= "<h4>".$data['orderdata']['address'].", ".$data['orderdata']['city'].", ".$data['orderdata']['postal'].", ".$country_zone['name']."<br>Floor: ".$data['orderdata']['floor'].", Name on the bell: ".$data['orderdata']['name_bell']."<br>Telephone: ".$data['userdata']['tel'].", Mobile: ".$data['userdata']['mob']."</h4>";
 } 
 } else {
  $cart .= "<h4>Collection from shop</h4>";
  $cart .= "<h4>You have chosen to receive your products from our headquarters.<br>Solon 135 Athens - Center PC 106 77<br>You can pick up from Monday to Friday from 09.00 to 17.00</h4>";
 }
  if ($data['orderdata']['pay_method']=='Cash') {
 $cart .= "<h4>Payment Method:</h4>";
 $cart .= "<h4>Pay cash on delivery</h4>";
 } elseif ($data['orderdata']['pay_method']=='Bank') {
 $cart .= "<h4>Payment Method:</h4>";
 $cart .= "<h4>Deposit amount on bank account</h4>";
 } elseif ($data['orderdata']['pay_method']=='Credit') {
 $cart .= "<h4>Payment Method:</h4>";
 $cart .= "<h4>Pay with credit card</h4>";
 } elseif ($data['orderdata']['pay_method']=='PayPal') {
 $cart .= "<h4>Payment Method:</h4>";
 $cart .= "<h4>Pay through Pay Pal</h4>";
 }

 $cart .= "<Br>";
  if ($data['orderdata']['receipt_type']=='receipt') {
 $cart .= "<h4>Receipt Type:</h4>";
 $cart .= "<h4>Receipt</h4>";
 } elseif ($data['orderdata']['receipt_type']=='invoice') {
 $cart .= "<h4>Receipt Type:</h4>";
 $cart .= "<h4>Invoice</h4>";
 $invoice_details = $this->MFuncs->getInvoiceDetails($data['orderdata']['id']);
 	if ($invoice_details) { 
	 $cart .= "<Br>";
	 $cart .= "<p>Company Name: ".$invoice_details['cmp_name']."<Br>";
	 $cart .= "Occupation: ".$invoice_details['cmp_occupation']."<Br>";
	 $cart .= "AFM: ".$invoice_details['cmp_afm']."<Br>";
	 $cart .= "Address: ".$invoice_details['cmp_address']."<Br>";
	 $cart .= "City: ".$invoice_details['cmp_city']."<Br>";
	 $cart .= "DOY: ".$invoice_details['cmp_doy']."</p>";
	}
 }
			$data['msg_title'] = "A new order has been made by ".$data['userdata']['fname']." ".$data['userdata']['lname'];
			$data['comments'] = "The order details are the following:".br(2).$cart;
			$data['post_msg'] = "";
			
			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);

			#Email send to the company!
			$this->email->from('no-reply@wines2u.gr', $data['userdata']['fname']." ".$data['userdata']['lname'].", ".$data['userdata']['email']);
			$this->email->to('info@wines2u.gr', 'www.wines2u.gr');
			$this->email->cc('b.a@wines2u.gr', 'www.wines2u.gr');
			$this->email->subject('www.wines2u.gr - Νέα Παραγγελία - New Order');
			$this->email->message($emsg);
			$this->email->send();
	
			$data['msg_title'] = "Dear ".$data['userdata']['fname']." ".$data['userdata']['lname'].",".br(1)."Thank you for choosing our online store for shopping. For any further clarification, please feel free to call us on 210 3800138.";
			$data['comments'] = "Your order details are the following:".br(2).$cart;
			$data['post_msg'] = "Communication Department".br(1);

			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);
		
			#Email send to the user
			$this->email->from('no-reply@wines2u.gr', 'www.wines2u.gr');
			$this->email->to($data['userdata']['email']);
			$this->email->subject('www.wines2u.gr - Νέα Παραγγελία - New Order');
			$this->email->message($emsg);
			$this->email->send();
			
		$data['order_cart'] = $cart;
}
		$this->MFuncs->finaliseOrderPayed($order_id);
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση παραγγελιών μέσω PayPal";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_orders';
	$data['orders'] = $this->MAdmins->getPayPalOrders();
//	$data['page_content'] = $this->MDashboard->getPageContent($id);
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
}
 function products(){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση products";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_products';
	$data['products'] = $this->MAdmins->getProducts();
	$data['search'] = false;
//	$data['page_content'] = $this->MDashboard->getPageContent($id);
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
function export_product_price() {
$query['data1'] = $this->MAdmins->getProducts();
$this->load->view('admin/excel_products_price',$query);
}
  function search_prd(){
		if($this->input->post('term')){
			$data['search'] = true;
			$data['products']=$this->MAdmins->search($this->input->post('term'));
		}else{
			$this->session->set_flashdata('message', 'Δεν συμπληρώσατε τίποτα για αναζήτηση');
			redirect('admin/categories/products', 'refresh');
		}
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση products";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_products';
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }

   function add_product(){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Προσθἠκη Προϊόντος";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_add_product';
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  } 
   function view_product($p_id){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Προβολή Προϊόντος";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_view_product';
	$data['product'] = $this->MAdmins->getProduct($p_id);
	$data['edit_id'] = '';
	$data['edit_det']=false;
	$data['edit']=false;
	$data['edit_photo']=false;
	$data['edit_cat']=false;
	$data['edit_subcat']=false;
	$data['edit_sub_subcat']=false;
//	$data['page_content'] = $this->MDashboard->getPageContent($id);
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }  
  function delete_product($p_id){
		$this->MAdmins->deleteProduct($p_id);
  		$this->session->set_flashdata('message','Η εγγραφή διαγράφηκε');
  		redirect('admin/categories/products','refresh');
	}
  function save_product(){
  if (($this->input->post('published')!='')){
	    $p_id = $this->MAdmins->saveProduct();
  		$this->session->set_flashdata('message','Οι αλλαγές αποθηκεύτηκαν');
  		redirect('admin/categories/view_product/'.$p_id,'refresh');
  }
  else {
  		$this->session->set_flashdata('message','Υπάρχει πρόβλημα στη προσθήκη του προϊόντος! Προσπαθήστε ξανά...');
  		redirect('admin/categories/add_product', '');
	}
	} 
  function update_product($p_id){
		$this->MAdmins->updateProduct($p_id);
  		$this->session->set_flashdata('message','ΟΙ αλλαγές αποθηκεύτηκαν');
  		redirect('admin/categories/view_product/'.$p_id,'refresh');
}
  function update_product_details($id, $p_id){
		$this->MAdmins->updateProductDetails($id, $p_id);
  		$this->session->set_flashdata('message','ΟΙ αλλαγές αποθηκεύτηκαν');
  		redirect('admin/categories/view_product/'.$p_id,'refresh');
}
  function edit_product($p_id){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Προβολή Προϊόντος";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_view_product';
	$data['product'] = $this->MAdmins->getProduct($p_id);
	$data['edit_id'] = $p_id;
	$data['edit_det']=false;
	$data['edit']=true;
	$data['edit_photo']=false;
	$data['edit_cat']=false;
	$data['edit_subcat']=false;
	$data['edit_sub_subcat']=false;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
   function edit_product_details($p_id, $id){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Προβολή Προϊόντος";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_view_product';
	$data['product'] = $this->MAdmins->getProduct($p_id);
	$data['edit_id'] = $id;
	$data['edit_det']=true;
	$data['edit']=false;
	$data['edit_photo']=false;
	$data['edit_cat']=false;
	$data['edit_subcat']=false;
	$data['edit_sub_subcat']=false;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  } 
    function update_product_cat($p_id){
		$this->MAdmins->updateProductCategory($p_id);
  		$this->session->set_flashdata('message','ΟΙ αλλαγές αποθηκεύτηκαν');
  		redirect('admin/categories/view_product/'.$p_id,'refresh');
}
   function edit_product_cat($p_id){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Προβολή Προϊόντος";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_view_product';
	$data['product'] = $this->MAdmins->getProduct($p_id);
	$data['edit_id'] = $p_id;
	$data['edit_det']=false;
	$data['edit']=false;
	$data['edit_photo']=false;
	$data['edit_cat']=true;
	$data['edit_subcat']=false;
	$data['edit_sub_subcat']=false;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  } 
     function edit_product_subcat($p_id){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Προβολή Προϊόντος";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_view_product';
	$data['hideColumn']="hideboth";
	$data['product'] = $this->MAdmins->getProduct($p_id);
	$data['edit_id'] = $p_id;
	$data['edit_det']=false;
	$data['edit']=false;
	$data['edit_photo']=false;
	$data['edit_cat']=false;
	$data['edit_subcat']=true;
	$data['edit_sub_subcat']=false;
//	$data['page_content'] = $this->MDashboard->getPageContent($id);
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  } 
    function update_product_subcat($p_id){
		$this->MAdmins->updateProductSubCategory($p_id);
  		$this->session->set_flashdata('message','ΟΙ αλλαγές αποθηκεύτηκαν');
  		redirect('admin/categories/view_product/'.$p_id,'refresh');
}
      function edit_product_sub_subcat($p_id){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Προβολή Προϊόντος";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_view_product';
	$data['hideColumn']="hideboth";
	$data['product'] = $this->MAdmins->getProduct($p_id);
	$data['edit_id'] = $p_id;
	$data['edit_det']=false;
	$data['edit']=false;
	$data['edit_photo']=false;
	$data['edit_cat']=false;
	$data['edit_subcat']=false;
	$data['edit_sub_subcat']=true;
//	$data['page_content'] = $this->MDashboard->getPageContent($id);
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  } 
   function update_product_sub_subcat($p_id){
		$this->MAdmins->updateProductSubSubCategory($p_id);
  		$this->session->set_flashdata('message','ΟΙ αλλαγές αποθηκεύτηκαν');
  		redirect('admin/categories/view_product/'.$p_id,'refresh');
}
   function xml_products(){
	$products = $this->MAdmins->getProducts();
	if ($products) {
	date_default_timezone_set("Europe/Athens");
	$now = date("Y-m-d G:i");

	$content = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
	$content .= '<mywebstore>'."\n";
	$content .= "\t".'<date>'.$now.'</date>'."\n";
	$content .= "\t".'<products>'."\n";
	foreach($products as $products=>$product){ 
	$category = $this->MAdmins->getProductCategoryName($product['p_id']);
	if ($category) {
	$content .= "\t\t".'<product>'."\n";
	$content .= "\t\t".'<id>'.$product['p_id'].'</id>'."\n";
	$content .= "\t\t\t".'<name><![CDATA['.$product['name'].']]></name>'."\n";
	$content .= "\t\t\t".'<link><![CDATA['.base_url().'view_product/'.$product['p_id'].']]></link>'."\n";
	$content .= "\t\t\t".'<image><![CDATA['.base_url().'images/prds/'.$product['image'].']]></image>'."\n";
	$content .= "\t\t\t".'<category id="'.$category['cat_id'].'"><![CDATA['.$category['cat_name'].']]></category>'."\n";
	$content .= "\t\t\t".'<price_with_vat>'.$product['price'].'</price_with_vat>'."\n";
	$content .= "\t\t\t".'<description><![CDATA['.$product['description'].']]></description>'."\n";
	$content .= "\t\t\t".'<instock>Y</instock>'."\n";
	$content .= "\t\t\t".'<availability>Κατόπιν Παραγγελίας</availability>'."\n";
	$content .= "\t\t".'</product>'."\n";
	}
	}
	$content .= "\t".'</products>'."\n";
	$content .= '</mywebstore>'."\n";
	}

	//$this->load->dbutil();
	//$query = $this->db->query("SELECT * FROM products inner join product_details on products.id=product_details.p_id");
	//$config = array (
    //              'root'    => 'root',
    //              'element' => 'element',
    //              'newline' => "\n",
    //              'tab'    => "\t"
    //            );
	//$data['results'] = $this->dbutil->xml_from_result($query, $config); 
	$this->load->helper('file');
	
	//$data = 'Some file data';
	if ( ! write_file('/home/getidbiz/public_html/wines2u/feeds/products.xml', $content))
	{
		$this->session->set_flashdata('message','Unable to write the file');
		redirect('admin/categories/xml_products_view','refresh');
	}
	else
	{
		$this->session->set_flashdata('message','File written!');
		redirect('admin/categories/xml_products_view','refresh');
	}
  }
 function xml_products_view(){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση products";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_xml_products';
	$this->load->helper('file'); 
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl'); 
  }
 function delete_xml($delfile){
 $old = array("_xml");
 $new   = array(".xml");

 $newphrase = str_replace($old, $new, $delfile);
 
	$DelFilePath = '/home/getidbiz/public_html/wines2u/feeds/'.$newphrase;
//	echo $DelFilePath;
//	break;
 if (file_exists($DelFilePath)) { unlink ($DelFilePath); 
 		$this->session->set_flashdata('message','The file is deleted');
		redirect('admin/categories/xml_products_view','refresh');
}
else {
		$this->session->set_flashdata('message','The file cannot be deleted');
		redirect('admin/categories/xml_products_view','refresh');
	 }
}

//    function update_company_subcat($cmp_id){
//		$this->MAdmins->updateCompanySubCategory($cmp_id);
//  		$this->session->set_flashdata('message','ΟΙ αλλαγές αποθηκεύτηκαν');
//  		redirect('admin/categories/view_company/'.$cmp_id,'refresh');
//}
//   function edit_company_subcat($cmp_id){
//	$data['liID']=$this->uri->segment(3);
//	$data['title'] = "Προβολή Εταιρίας";
//	$data['hideColumn']="hideboth";
//	$data['main'] = 'admin/pages_view_company';
//	$data['company'] = $this->MAdmins->getCompany($cmp_id);
//	$data['edit_id'] = $cmp_id;
//	$data['edit_det']=false;
//	$data['edit']=false;
//	$data['edit_photo']=false;
//	$data['edit_cat']=false;
//	$data['edit_subcat']=true;
//	$this->load->vars($data);
//	$this->load->view('admin/dashboard_tpl');  
//  } 
  function upload_product_photo($p_id){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Προβολή Προϊόντος";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_view_product';
	$data['hideColumn']="hideboth";
	$data['product'] = $this->MAdmins->getProduct($p_id);
	$data['edit_id'] = '';
	$data['edit_det']=false;
	$data['edit']=false;
	$data['edit_photo']=true;
	$data['edit_cat']=false;
	$data['edit_subcat']=false;
	$data['edit_sub_subcat']=false;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
function upload_product_photos($p_id){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Προσθἠκη Φωτογραφιών";
	$data['hideColumn']="hideboth";
	$data['productphotos'] = $this->MAdmins->getProductPhotos($p_id);
	$data['p_id']=$p_id;
	$data['main'] = 'admin/pages_product_photos';
	$data['hideColumn']="hideboth";
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  } 
function delete_photo($photo_id){
		$userphoto = $this->MAdmins->getProductPhotos2($photo_id);
		 $DelFilePath ='/home/getidbiz/public_html/wines2u/images/prds/'.$userphoto['photo_image'];
 if (file_exists($DelFilePath)) { unlink ($DelFilePath); }
		 $DelFilePath = '/home/getidbiz/public_html/wines2u/images/prds/thumb/'.$userphoto['photo_image'];
 if (file_exists($DelFilePath)) { unlink ($DelFilePath); }
	$this->MAdmins->deletePhoto($photo_id);
			$this->session->set_flashdata('message', 'Η Φωτογραφία Διαγράφηκε');
			redirect('admin/categories/upload_product_photos/'.$userphoto['photo_p_id'],'refresh'); 
}
  function product_offers(){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Προσφορών Προϊόντων";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_product_offers';
	$data['hideColumn']="hideboth";
	$data['products'] = $this->MAdmins->getProducts();
	$data['edit']=false;
	$data['search'] = false;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
  function search_prd_offer(){
		if($this->input->post('term')){
			$data['search'] = true;
			$data['products']=$this->MAdmins->search($this->input->post('term'));
		}else{
			$this->session->set_flashdata('message', 'Δεν συμπληρώσατε τίποτα για αναζήτηση');
			redirect('admin/categories/products', 'refresh');
		}
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Προσφορών Προϊόντων";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_product_offers';
	$data['hideColumn']="hideboth";
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }
function update_product_offers(){
		$this->MAdmins->updateProductOffers();
  		$this->session->set_flashdata('message','ΟΙ αλλαγές αποθηκεύτηκαν');
  		redirect('admin/categories/product_offers','refresh');
	}



	function upload_photo($p_id){
		ini_set("memory_limit","80M");
		$photo = $this->input->post('photo');
		$id= $this->session->userdata('ses_user_id');
			$config['upload_path'] = './prds/';
			$config['allowed_types'] = 'jpg|png|gif|jpeg';
			$config['max_size'] = '10000';
			$config['remove_spaces'] = true;
			$config['overwrite'] = true;
			$config['max_width'] = '0';
			$config['max_height'] = '0';
			
			$this->load->library('upload', $config);
			if(!$this->upload->do_upload('photo')){
			$this->upload->display_errors();
			$this->session->set_flashdata('message','Υπήρξε πρόβλημα στην αποθήκευση της φωτογραφίας');
		    redirect('admin/categories/upload_product_photo/'.$p_id,'refresh');
			exit();
			}
			
			$photo = $this->upload->data();
			//if ($photo['file_name']){
			//$data['photo'] = "/users/".$photo['file_name'];
			$new_name=$this->MAdmins->RenamePhoto($photo['file_name'], $p_id);
			//rename("./users/" . $photo['file_name'], "./images/users/" . $new_name);
			$this->MAdmins->InsertPicture($new_name, $p_id);


list($width, $height, $type, $attr) = getimagesize("./prds/" . $photo['file_name']);


      $this->load->library('image_lib');
      if (($width > 640) && ($width>$height))
      {
        //resize image
        $config['image_library'] = 'GD2';
        $config['source_image'] = './prds/' . $photo['file_name'];
        $config['new_image'] = './images/prds/' . $new_name;
		$config['create_thumb'] = FALSE;
        $config['maintain_ratio'] = TRUE;
        //if ($width>height) {
		$config['width'] = 640;//180
		$config['height'] = 480;
        $config['quality'] = 90;
		$config['master_dim'] = 'width';
        $this->image_lib->initialize($config);
        $this->load->library('image_lib', $config);
        if(!$this->image_lib->resize())
        {
          echo $this->image_lib->display_errors();
        }
		 $DelFilePath = '/home/getidbiz/public_html/wines2u/prds/'.$photo['file_name'];
         # delete file if exists
         if (file_exists($DelFilePath)) { unlink ($DelFilePath); }
      } 
	  elseif (($height > 480) && ($height>$width)) {
        //resize image
        $config['image_library'] = 'GD2';
        $config['source_image'] = './prds/' . $photo['file_name'];
        $config['new_image'] = './images/prds/' . $new_name;
		$config['create_thumb'] = FALSE;
        $config['maintain_ratio'] = TRUE;
        //if ($width>height) {
		$config['width'] = 360;//180
		$config['height'] = 480;
        $config['quality'] = 90;
		$config['master_dim'] = 'height';
        $this->image_lib->initialize($config);
        $this->load->library('image_lib', $config);
        if(!$this->image_lib->resize())
        {
          echo $this->image_lib->display_errors();
        }
		 $DelFilePath = '/home/getidbiz/public_html/wines2u/prds/'.$photo['file_name'];
         # delete file if exists
         if (file_exists($DelFilePath)) { unlink ($DelFilePath); }
	  } 
	  elseif (($width==$height) && ($height>480)) {
        //resize image
        $config['image_library'] = 'GD2';
        $config['source_image'] = './prds/' . $photo['file_name'];
        $config['new_image'] = './images/prds/' . $new_name;
		$config['create_thumb'] = FALSE;
        $config['maintain_ratio'] = TRUE;
        //if ($width>height) {
		$config['width'] = 480;//180
		$config['height'] = 480;
        $config['quality'] = 90;
		$config['master_dim'] = 'widht';
        $this->image_lib->initialize($config);
        $this->load->library('image_lib', $config);
        if(!$this->image_lib->resize())
        {
          echo $this->image_lib->display_errors();
        }
		 $DelFilePath = '/home/getidbiz/public_html/wines2u/prds/'.$photo['file_name'];
         # delete file if exists
         if (file_exists($DelFilePath)) { unlink ($DelFilePath); }
	  }
      else
      {
        $source = './prds/' . $photo['file_name'];
        $destination = './images/prds/' . $new_name;
        rename($source, $destination);
      }
      //create thumbnail
      $config['image_library'] = 'GD2';
      $config['source_image'] = './images/prds/' . $new_name;
      $config['new_image'] = './images/prds/thumb/' . $new_name;
      $config['create_thumb'] = TRUE;
      $config['thumb_marker'] = '';
      $config['maintain_ratio'] = TRUE;
      $config['width'] = 200;//180
      $config['height'] = 150;
      $config['master_dim'] = 'width';
      $this->image_lib->initialize($config);
      $this->load->library('image_lib', $config);
      $this->image_lib->resize();
redirect('admin/categories/view_product/'.$p_id,'refresh');
}
		function upload_company_photos_save($cmp_id){
	ini_set("memory_limit","80M");
		$photo = $this->input->post('photo');
			$config['upload_path'] = './cmps/';
			$config['allowed_types'] = 'jpg|png|gif|jpeg';
			$config['max_size'] = '10000';
			$config['remove_spaces'] = true;
			$config['overwrite'] = true;
			$config['max_width'] = '0';
			$config['max_height'] = '0';
			
			$this->load->library('upload', $config);
			if(!$this->upload->do_upload('photo')){
			$this->upload->display_errors();
			$this->session->set_flashdata('message','Υπήρξε πρόβλημα στην αποθήκευση της φωτογραφίας');
		    redirect('admin/categories/upload_company_photos/'.$cmp_id,'refresh');
			exit();
			}
			
			$photo = $this->upload->data();
			//if ($photo['file_name']){
			//$data['photo'] = "/users/".$photo['file_name'];
			 $a = uniqid(rand(), true);
			 $new=$cmp_id."_".$a;
			$new_name=$this->MAdmins->RenamePhoto($photo['file_name'], $new);
			//rename("./users/" . $photo['file_name'], "./images/users/" . $new_name);
			$this->MAdmins->InsertPicturesMore($new_name, $cmp_id);


list($width, $height, $type, $attr) = getimagesize("./cmps/" . $photo['file_name']);


      $this->load->library('image_lib');
      if (($width > 640) && ($width>$height))
      {
        //resize image
        $config['image_library'] = 'GD2';
        $config['source_image'] = './cmps/' . $photo['file_name'];
        $config['new_image'] = './images/cmps/' . $new_name;
		$config['create_thumb'] = FALSE;
        $config['maintain_ratio'] = TRUE;
        //if ($width>height) {
		$config['width'] = 640;//180
		$config['height'] = 480;
        $config['quality'] = 90;
		$config['master_dim'] = 'width';
        $this->image_lib->initialize($config);
        $this->load->library('image_lib', $config);
        if(!$this->image_lib->resize())
        {
          echo $this->image_lib->display_errors();
        }
		 $DelFilePath = '/home/getidbiz/public_html/wines2u/cmps/'.$photo['file_name'];
         # delete file if exists
         if (file_exists($DelFilePath)) { unlink ($DelFilePath); }
      } 
	  elseif (($height > 480) && ($height>$width)) {
        //resize image
        $config['image_library'] = 'GD2';
        $config['source_image'] = './cmps/' . $photo['file_name'];
        $config['new_image'] = './images/cmps/' . $new_name;
		$config['create_thumb'] = FALSE;
        $config['maintain_ratio'] = TRUE;
        //if ($width>height) {
		$config['width'] = 360;//180
		$config['height'] = 480;
        $config['quality'] = 90;
		$config['master_dim'] = 'height';
        $this->image_lib->initialize($config);
        $this->load->library('image_lib', $config);
        if(!$this->image_lib->resize())
        {
          echo $this->image_lib->display_errors();
        }
		 $DelFilePath = '/home/getidbiz/public_html/wines2u/cmps/'.$photo['file_name'];
         # delete file if exists
         if (file_exists($DelFilePath)) { unlink ($DelFilePath); }
	  } 
	  elseif (($width==$height) && ($height>480)) {
        //resize image
        $config['image_library'] = 'GD2';
        $config['source_image'] = './cmps/' . $photo['file_name'];
        $config['new_image'] = './images/cmps/' . $new_name;
		$config['create_thumb'] = FALSE;
        $config['maintain_ratio'] = TRUE;
        //if ($width>height) {
		$config['width'] = 480;//180
		$config['height'] = 480;
        $config['quality'] = 90;
		$config['master_dim'] = 'width';
        $this->image_lib->initialize($config);
        $this->load->library('image_lib', $config);
        if(!$this->image_lib->resize())
        {
          echo $this->image_lib->display_errors();
        }
		 $DelFilePath = '/home/getidbiz/public_html/wines2u/cmps/'.$photo['file_name'];
         # delete file if exists
         if (file_exists($DelFilePath)) { unlink ($DelFilePath); }
	  }
      else
      {
        $source = './cmps/' . $photo['file_name'];
        $destination = './images/cmps/' . $new_name;
        rename($source, $destination);
      }

      //create thumbnail
      $config['image_library'] = 'GD2';
      $config['source_image'] = './images/cmps/' . $new_name;
      $config['new_image'] = './images/cmps/thumb/' . $new_name;
      $config['create_thumb'] = TRUE;
      $config['thumb_marker'] = '';
      $config['maintain_ratio'] = TRUE;
      $config['width'] = 200;//180
      $config['height'] = 150;
      $config['master_dim'] = 'width';
      $this->image_lib->initialize($config);
      $this->load->library('image_lib', $config);
      $this->image_lib->resize();

      redirect('admin/categories/upload_company_photos/'.$cmp_id,'refresh');
		//redirect('profile','refresh');
  	}
	function upload_product_photos_save($p_id){
		ini_set("memory_limit","80M");
		$photo = $this->input->post('photo');
		$id= $this->session->userdata('ses_user_id');
			$config['upload_path'] = './prds/';
			$config['allowed_types'] = 'jpg|png|gif|jpeg';
			$config['max_size'] = '10000';
			$config['remove_spaces'] = true;
			$config['overwrite'] = true;
			$config['max_width'] = '0';
			$config['max_height'] = '0';
			
			$this->load->library('upload', $config);
			if(!$this->upload->do_upload('photo')){
			$this->upload->display_errors();
			$this->session->set_flashdata('message','Υπήρξε πρόβλημα στην αποθήκευση της φωτογραφίας');
		    redirect('admin/categories/upload_product_photos/'.$p_id,'refresh');
			exit();
			}
			
			$photo = $this->upload->data();
			//if ($photo['file_name']){
			//$data['photo'] = "/users/".$photo['file_name'];
			$a = uniqid(rand(), true);
	        $new=$p_id."_".$a;
			$new_name=$this->MAdmins->RenamePhoto($photo['file_name'], $new);
			//rename("./users/" . $photo['file_name'], "./images/users/" . $new_name);
			$this->MAdmins->InsertPicturesMore($new_name, $p_id);

list($width, $height, $type, $attr) = getimagesize("./prds/" . $photo['file_name']);


      $this->load->library('image_lib');
      if (($width > 640) && ($width>$height))
      {
        //resize image
        $config['image_library'] = 'GD2';
        $config['source_image'] = './prds/' . $photo['file_name'];
        $config['new_image'] = './images/prds/' . $new_name;
		$config['create_thumb'] = FALSE;
        $config['maintain_ratio'] = TRUE;
        //if ($width>height) {
		$config['width'] = 640;//180
		$config['height'] = 480;
        $config['quality'] = 90;
		$config['master_dim'] = 'width';
        $this->image_lib->initialize($config);
        $this->load->library('image_lib', $config);
        if(!$this->image_lib->resize())
        {
          echo $this->image_lib->display_errors();
        }
		 $DelFilePath = '/home/getidbiz/public_html/wines2u/prds/'.$photo['file_name'];
         # delete file if exists
         if (file_exists($DelFilePath)) { unlink ($DelFilePath); }
      } 
	  elseif (($height > 480) && ($height>$width)) {
        //resize image
        $config['image_library'] = 'GD2';
        $config['source_image'] = './prds/' . $photo['file_name'];
        $config['new_image'] = './images/prds/' . $new_name;
		$config['create_thumb'] = FALSE;
        $config['maintain_ratio'] = TRUE;
        //if ($width>height) {
		$config['width'] = 360;//180
		$config['height'] = 480;
        $config['quality'] = 90;
		$config['master_dim'] = 'height';
        $this->image_lib->initialize($config);
        $this->load->library('image_lib', $config);
        if(!$this->image_lib->resize())
        {
          echo $this->image_lib->display_errors();
        }
		 $DelFilePath = '/home/getidbiz/public_html/wines2u/prds/'.$photo['file_name'];
         # delete file if exists
         if (file_exists($DelFilePath)) { unlink ($DelFilePath); }
	  } 
	  elseif (($width==$height) && ($height>480)) {
        //resize image
        $config['image_library'] = 'GD2';
        $config['source_image'] = './prds/' . $photo['file_name'];
        $config['new_image'] = './images/prds/' . $new_name;
		$config['create_thumb'] = FALSE;
        $config['maintain_ratio'] = TRUE;
        //if ($width>height) {
		$config['width'] = 480;//180
		$config['height'] = 480;
        $config['quality'] = 90;
		$config['master_dim'] = 'widht';
        $this->image_lib->initialize($config);
        $this->load->library('image_lib', $config);
        if(!$this->image_lib->resize())
        {
          echo $this->image_lib->display_errors();
        }
		 $DelFilePath = '/home/getidbiz/public_html/wines2u/prds/'.$photo['file_name'];
         # delete file if exists
         if (file_exists($DelFilePath)) { unlink ($DelFilePath); }
	  }
      else
      {
        $source = './prds/' . $photo['file_name'];
        $destination = './images/prds/' . $new_name;
        rename($source, $destination);
      }
      //create thumbnail
      $config['image_library'] = 'GD2';
      $config['source_image'] = './images/prds/' . $new_name;
      $config['new_image'] = './images/prds/thumb/' . $new_name;
      $config['create_thumb'] = TRUE;
      $config['thumb_marker'] = '';
      $config['maintain_ratio'] = TRUE;
      $config['width'] = 200;//180
      $config['height'] = 150;
      $config['master_dim'] = 'width';
      $this->image_lib->initialize($config);
      $this->load->library('image_lib', $config);
      $this->image_lib->resize();
redirect('admin/categories/upload_product_photos/'.$p_id,'refresh');
}

//////////////////////////////////////
//////////////////////////////////////


  function search_hotel(){
		if($this->input->post('term')){
			$data['search'] = true;
			$data['hotels']=$this->MAdmins->search($this->input->post('term'));
		}else{
			$this->session->set_flashdata('message', $this->lang->line('not_enter_search'));
			redirect('admin/categories/quality_hotels', 'refresh');
		}
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση Quality Hotels";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_quality_hotels';
	$data['hideColumn']="hideboth";
	//$data['hotels'] = $this->MAdmins->getHotels();
//	$data['page_content'] = $this->MDashboard->getPageContent($id);
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
  }




  		function upload_slide_photo(){
	ini_set("memory_limit","80M");
		$photo = $this->input->post('photo');
			$config['upload_path'] = './slideshow/';
			$config['allowed_types'] = 'jpg|png|gif|jpeg';
			$config['max_size'] = '0';
			$config['remove_spaces'] = true;
			$config['overwrite'] = true;
			$config['max_width'] = '0';
			$config['max_height'] = '0';
			
			$this->load->library('upload', $config);
			if(!$this->upload->do_upload('photo')){
			$this->upload->display_errors();
			$this->session->set_flashdata('message','Υπήρξε πρόβλημα στην αποθήκευση της φωτογραφίας');
		    redirect('admin/categories/add_slideshow','refresh');
			exit();
			}
			
			$photo = $this->upload->data();
			//if ($photo['file_name']){
			//$data['photo'] = "/users/".$photo['file_name'];
			 $a = uniqid(rand(), true);
			 $new= $a;
			$new_name=$this->MAdmins->RenamePhoto($photo['file_name'], $new);
			//rename("./users/" . $photo['file_name'], "./images/users/" . $new_name);
			$photo_id = $this->MAdmins->InsertSlidePicture($new_name);


list($width, $height, $type, $attr) = getimagesize("./slideshow/" . $photo['file_name']);


      $this->load->library('image_lib');
      if (($width > 750) || ($height > 300))
      {
        //resize image
        $config['image_library'] = 'GD2';
        $config['source_image'] = './slideshow/' . $photo['file_name'];
        $config['new_image'] = './images/slideshow/' . $new_name;
		$config['create_thumb'] = FALSE;
        $config['maintain_ratio'] = FALSE;
        //if ($width>height) {
		$config['width'] = 750;//180
		$config['height'] = 300;
        $config['quality'] = 90;
		$config['master_dim'] = 'width';
        $this->image_lib->initialize($config);
        $this->load->library('image_lib', $config);
        if(!$this->image_lib->resize())
        {
          echo $this->image_lib->display_errors();
        }
		 $DelFilePath = '/home/getidbiz/public_html/wines2u/images/slideshow/'.$photo['file_name'];
         # delete file if exists
         if (file_exists($DelFilePath)) { unlink ($DelFilePath); }
      }
      else
      {
        $source = './slideshow/' . $photo['file_name'];
        $destination = './images/slideshow/' . $new_name;
        rename($source, $destination);
      }

      //create thumbnail
      $config['image_library'] = 'GD2';
      $config['source_image'] = './images/slideshow/' . $new_name;
      $config['new_image'] = './images/slideshow/thumb/' . $new_name;
      $config['create_thumb'] = TRUE;
      $config['thumb_marker'] = '';
      $config['maintain_ratio'] = TRUE;
      $config['width'] = 180;//180
      $config['height'] = 100;
      $config['master_dim'] = 'width';
      $this->image_lib->initialize($config);
      $this->load->library('image_lib', $config);
      $this->image_lib->resize();

      redirect('admin/categories/save_slideshow/'.$photo_id,'refresh');
		//redirect('profile','refresh');
  	}
	
function save_slideshow($photo_id){
	$data['liID']=$this->uri->segment(3);
	$data['title'] = "Διαχείριση link Home Page";
	$data['hideColumn']="hideboth";
	$data['main'] = 'admin/pages_home';
	$data['hideColumn']="hideboth";
	$data['slidephotos'] = $this->MAdmins->getSlidePhotos();
	$data['content'] = $this->MAdmins->getPage(3);
	$data['edit_id'] = '';
	$data['edit']=false;
	$data['add_slide']=false;
	$data['add_slide2']=true;
	$data['photo_id'] = $photo_id;
	$this->load->vars($data);
	$this->load->view('admin/dashboard_tpl');  
}
function save_slide_details($photo_id){
	  if (($this->input->post('hotel')) && ($this->input->post('published'))){
     	$this->MAdmins->save_slide_details($photo_id);
  		$this->session->set_flashdata('message','ΟΙ αλλαγές αποθηκεύτηκαν');
  		redirect('admin/categories/home_page','refresh');
	  } else { 
	    $this->session->set_flashdata('message','Δεν συμπληρώσατε όλα τα απαρραίτητα πεδία');
  		redirect('admin/categories/save_slideshow/'.$photo_id,'refresh');
	  }
}
	      function delete_sliephoto($photo_id){
		$userphoto = $this->MAdmins->getSlidePhotos2($photo_id);
		 $DelFilePath = '/home/getidbiz/public_html/wines2u/images/slideshow/'.$userphoto['photo_image'];
 if (file_exists($DelFilePath)) { unlink ($DelFilePath); }
		 $DelFilePath = '/home/getidbiz/public_html/wines2u/images/slideshow/thumb/'.$userphoto['photo_image'];
 if (file_exists($DelFilePath)) { unlink ($DelFilePath); }
	$this->MAdmins->deleteSlideshowPhoto($photo_id);
			$this->session->set_flashdata('message', 'Η Φωτογραφία Διαγράφηκε');
			redirect('admin/categories/home_page','refresh'); 
}


 
}//end class
?>