<?php

class MAdmins extends Model{

	function MAdmins(){
		parent::Model();
	}
	  function getKeywords(){
    $data = array();
		$this->db->select('*');
		$this->db->from('keywords');
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();    
    return $data;    
 }
function updateKeywords($id){
      $data = array('keywords' => $this->input->post('keywords')
                    );
	  $this->db->where('id',$id);
	  $this->db->update('keywords',$data);
	}


	function verifyUser($u,$pw){
		$this->db->select('id,username');
		$this->db->where('username',$u);
		$this->db->where('password', md5($pw));
		$this->db->where('status', 'active');
		$this->db->limit(1);
		$Q = $this->db->get('users');
		$this->session->set_userdata('lastquery', $this->db->last_query());
		if ($Q->num_rows() > 0){
			$row = $Q->row_array();
			return $row;
		}else{
			$this->session->set_flashdata('error', 'Sorry, try again!');	
			return array();
		}		
	}
	  function getPage($id){
    $data = array();
		$this->db->select('*');
		$this->db->from('pages');
		$this->db->where('path',$id);
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
     }

    $Q->free_result();    
    return $data;    
 }
	  function getPages(){
    $data = array();
		$this->db->select('*');
		$this->db->from('pages');
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
     }

    $Q->free_result();    
    return $data;    
 }
	  function getPagesbySection($section){
    $data = array();
		$this->db->select('*');
		$this->db->from('pages');
		$this->db->where("section",$section);
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
     }

    $Q->free_result();    
    return $data;    
 }
function addPagebySection($section){
	date_default_timezone_set("Europe/Athens");
	$now = date("Y-m-d G:i:s");
		$this->db->select('*');
		$this->db->from('languages');
		 $this->db->orderby("lang_id","asc");
	$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
      $data = array('name' => $this->input->post('name'.$row['lang_id']),
	  				'title' => $this->input->post('title'.$row['lang_id']),
					'content' => $this->input->post('content'.$row['lang_id']),
					'keywords' => $this->input->post('keywords'.$row['lang_id']),
	  				'order' => $this->input->post('order'.$row['lang_id']),
                    'lang_id' => $row['lang_id'],
					'section' => $section,
					'status' => 'active'
					);
	  $this->db->insert('pages',$data);
	   }
     }
    $Q->free_result();    
	}
function addPagebySectionTop($section){
	date_default_timezone_set("Europe/Athens");
	$now = date("Y-m-d G:i:s");
		$this->db->select('*');
		$this->db->from('languages');
		 $this->db->orderby("lang_id","asc");
	$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
      $data = array('name' => $this->input->post('name'.$row['lang_id']),
	  				'path' => $this->input->post('cat_url_title'.$row['lang_id']),
	  				'title' => $this->input->post('title'.$row['lang_id']),
					'content' => $this->input->post('content'.$row['lang_id']),
					'keywords' => $this->input->post('keywords'.$row['lang_id']),
	  				'order' => $this->input->post('order'.$row['lang_id']),
                    'lang_id' => $row['lang_id'],
					'section' => $section,
					'status' => 'active'
					);
	  $this->db->insert('pages',$data);
	   }
     }
    $Q->free_result();    
	}
function getOrders(){
    $data = array();
		$this->db->select('*');
		$this->db->from('orders');
		$this->db->where("completed","Yes");
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
     }

    $Q->free_result();    
    return $data;    
 }
function getPayPalOrders(){
    $data = array();
		$this->db->select('*');
		$this->db->from('orders');
		//$this->db->where("completed","Yes");
		$this->db->where("pay_method","PayPal");
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
     }

    $Q->free_result();    
    return $data;    
 }
 function getProductDetailsbyID($id){
   		$ld=$this->session->userdata('lang_id');
			 $data = array();
		$this->db->select('*');
		$this->db->from('products');
		$this->db->join('product_details','product_details.p_id=products.id', 'left');
		$this->db->where('product_details.lang_id',$ld);
		$this->db->where("products.id",$id);
		$this->db->limit(1);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }

    $Q->free_result();    
    return $data;    
 }

function getClient($id){
    $data = array();
		$this->db->select('*');
		$this->db->from('clients');
		$this->db->where('id',id_clean($id));
		$this->db->limit(1);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }

    $Q->free_result();    
    return $data;    
 }
function getOrder($id){
    $data = array();
		$this->db->select('*');
		$this->db->from('orders');
		$this->db->where('id',id_clean($id));
		$this->db->limit(1);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }

    $Q->free_result();    
    return $data;    
 }
function getPagebyID($id){
    $data = array();
		$this->db->select('*');
		$this->db->from('pages');
		$this->db->where('id',id_clean($id));
		$this->db->limit(1);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }

    $Q->free_result();    
    return $data;    
 }
	function updateOrderSent($order_id, $status){
      $data = array('sent' => $status
                    );
	  $this->db->where('id',$order_id);
	  $this->db->update('orders',$data);	
	}
	function updateOrderPayed($order_id, $status){
      $data = array('payed' => $status
                    );
	  $this->db->where('id',$order_id);
	  $this->db->update('orders',$data);	
	}
	function updatePage($id){
      $data = array('name' => $this->input->post('name'),
	  				'title' => $this->input->post('title'),
                    'content' => $this->input->post('content'),
                    'keywords' => $this->input->post('keywords'),
					'order' => $this->input->post('order')
                    );
	  $this->db->where('id',$id);
	  $this->db->update('pages',$data);	
	
	}
	function updatePageTop($id){
      $data = array('name' => $this->input->post('name'),
	  	  			'path' => $this->input->post('cat_url_title'),
	  				'title' => $this->input->post('title'),
                    'content' => $this->input->post('content'),
                    'keywords' => $this->input->post('keywords'),
					'order' => $this->input->post('order')
                    );
	  $this->db->where('id',$id);
	  $this->db->update('pages',$data);	
	
	}
 function getLanguages(){
    $data = array();
		$this->db->select('*');
		$this->db->from('languages');
	 $this->db->orderby("lang_id","asc");
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
     }

    $Q->free_result();    
    return $data;    
 }
	  function getRightCategories(){
    $data = array();
		$this->db->select('*');
		$this->db->from('right_category');
		 $this->db->orderby("name","asc");
		$this->db->groupby('right_cat_id');
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
     }
    $Q->free_result();    
    return $data;    
 }
	  function getCategories(){
    $data = array();
		$this->db->select('*');
		$this->db->from('category');
		 $this->db->orderby("cat_name","asc");
		$this->db->groupby('cat_id');
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
     }
    $Q->free_result();    
    return $data;    
 }
	  function getVarieties(){
    $data = array();
		$this->db->select('*');
		$this->db->from('varieties');
		 $this->db->orderby("name","asc");
		$this->db->groupby('var_id');
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
     }
    $Q->free_result();    
    return $data;    
 }
	  function getNews(){
    $data = array();
		$this->db->select('*');
		$this->db->from('news');
		 $this->db->orderby("order","asc");
		$this->db->groupby('new_id');
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
     }
    $Q->free_result();    
    return $data;    
 }
function addCategory(){
	date_default_timezone_set("Europe/Athens");
	$now = date("Y-m-d G:i:s");
		$this->db->select('*');
		$this->db->from('languages');
		 $this->db->orderby("lang_id","asc");
	$Q=$this->db->get();
     if ($Q->num_rows() > 0){
		 $c=1;
       foreach ($Q->result_array() as $row){
		    if ($c==1) {
      $data = array('cat_name' => $this->input->post('name'.$row['lang_id']),
	  				'order' => $this->input->post('order'.$row['lang_id']),
	  				'home_page' => $this->input->post('home_page'),
                    'lang_id' => $row['lang_id'],
					'date_added' => $now
                    );
	  $this->db->insert('category',$data);
		       					$data2 = array();
								$Q5 = $this->db->query('SELECT LAST_INSERT_ID()');
								if ($Q5->num_rows() > 0){
								   $data2 = $Q5->row_array();
								}
								$Q5->free_result();
								$cat_id = $data2;
					$c_id=$cat_id['LAST_INSERT_ID()'];
				    $data = array('cat_id' => $c_id
								  );
	  $this->db->where('id',$c_id);
	  $this->db->update('category',$data);	
			} else {
				      $data = array('cat_name' => $this->input->post('name'.$row['lang_id']),
					 'cat_id' => $c_id,
 	  				'home_page' => $this->input->post('home_page'),
                   'lang_id' => $row['lang_id'],
					'date_added' => $now
                    );
	  $this->db->insert('category',$data);
	         }
			 	  $c++;
	   }
     }
    $Q->free_result();    
	}
function addVariety(){
	date_default_timezone_set("Europe/Athens");
	$now = date("Y-m-d G:i:s");
		$this->db->select('*');
		$this->db->from('languages');
		 $this->db->orderby("lang_id","asc");
	$Q=$this->db->get();
     if ($Q->num_rows() > 0){
		 $c=1;
       foreach ($Q->result_array() as $row){
		    if ($c==1) {
      $data = array('name' => $this->input->post('name'.$row['lang_id']),
	  				'text' => $this->input->post('text'.$row['lang_id']),
                    'lang_id' => $row['lang_id'],
					'date_added' => $now
                    );
	  $this->db->insert('varieties',$data);
		       					$data2 = array();
								$Q5 = $this->db->query('SELECT LAST_INSERT_ID()');
								if ($Q5->num_rows() > 0){
								   $data2 = $Q5->row_array();
								}
								$Q5->free_result();
								$cat_id = $data2;
					$c_id=$cat_id['LAST_INSERT_ID()'];
				    $data = array('var_id' => $c_id
								  );
	  $this->db->where('id',$c_id);
	  $this->db->update('varieties',$data);	
			} else {
				      $data = array('name' => $this->input->post('name'.$row['lang_id']),
					  'text' => $this->input->post('text'.$row['lang_id']),
					 'var_id' => $c_id,
                    'lang_id' => $row['lang_id'],
					'date_added' => $now
                    );
	  $this->db->insert('varieties',$data);
	         }
			 	  $c++;
	   }
     }
    $Q->free_result();    
	}
function addRightCategory(){
	date_default_timezone_set("Europe/Athens");
	$now = date("Y-m-d G:i:s");
		$this->db->select('*');
		$this->db->from('languages');
		 $this->db->orderby("lang_id","asc");
	$Q=$this->db->get();
     if ($Q->num_rows() > 0){
		 $c=1;
       foreach ($Q->result_array() as $row){
		    if ($c==1) {
      $data = array('name' => $this->input->post('name'.$row['lang_id']),
	  				'order' => $this->input->post('order'.$row['lang_id']),
                    'lang_id' => $row['lang_id'],
					'date_added' => $now
                    );
	  $this->db->insert('right_category',$data);
		       					$data2 = array();
								$Q5 = $this->db->query('SELECT LAST_INSERT_ID()');
								if ($Q5->num_rows() > 0){
								   $data2 = $Q5->row_array();
								}
								$Q5->free_result();
								$cat_id = $data2;
					$c_id=$cat_id['LAST_INSERT_ID()'];
				    $data = array('right_cat_id' => $c_id
								  );
	  $this->db->where('id',$c_id);
	  $this->db->update('right_category',$data);	
			} else {
				      $data = array('name' => $this->input->post('name'.$row['lang_id']),
					 'right_cat_id' => $c_id,
                    'lang_id' => $row['lang_id'],
					'date_added' => $now
                    );
	  $this->db->insert('right_category',$data);
	         }
			 	  $c++;
	   }
     }
    $Q->free_result();    
	}
function addNew(){
	date_default_timezone_set("Europe/Athens");
	$now = date("Y-m-d G:i:s");
		$this->db->select('*');
		$this->db->from('languages');
		 $this->db->orderby("lang_id","asc");
	$Q=$this->db->get();
     if ($Q->num_rows() > 0){
		 $c=1;
       foreach ($Q->result_array() as $row){
		    if ($c==1) {
      $data = array('title' => $this->input->post('title'.$row['lang_id']),
	  				'longdesc' => $this->input->post('description'.$row['lang_id']),
					'order' => $this->input->post('order'.$row['lang_id']),
                    'lang_id' => $row['lang_id'],
					'date' => $now
                    );
	  $this->db->insert('news',$data);
		       					$data2 = array();
								$Q5 = $this->db->query('SELECT LAST_INSERT_ID()');
								if ($Q5->num_rows() > 0){
								   $data2 = $Q5->row_array();
								}
								$Q5->free_result();
								$new_id = $data2;
					$c_id=$new_id['LAST_INSERT_ID()'];
				    $data = array('new_id' => $c_id
								  );
	  $this->db->where('id',$c_id);
	  $this->db->update('news',$data);	
			} else {
				      $data = array('title' => $this->input->post('title'.$row['lang_id']),
	  				'longdesc' => $this->input->post('description'.$row['lang_id']),
					'order' => $this->input->post('order'.$row['lang_id']),
					 'new_id' => $c_id,
                    'lang_id' => $row['lang_id'],
					'date' => $now
                    );
	  $this->db->insert('news',$data);
	         }
			 	  $c++;
	   }
     }
    $Q->free_result();    
	}
function updateCategory($id, $cat_id){
					$this->db->select('*');
		$this->db->from('languages');
		 $this->db->orderby("lang_id","asc");
	$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
      $data = array('cat_name' => $this->input->post('name'.$row['lang_id']),
	  'order' => $this->input->post('order'.$row['lang_id']),
		'home_page' => $this->input->post('home_page')
                    );
	  $this->db->where('cat_id',$cat_id);
	  $this->db->where('lang_id',$row['lang_id']);
	  $this->db->update('category',$data);
	   }
     }
    $Q->free_result();    
	}
function updateVariety($id, $var_id){
					$this->db->select('*');
		$this->db->from('languages');
		 $this->db->orderby("lang_id","asc");
	$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
      $data = array('name' => $this->input->post('name'.$row['lang_id']),
	  'text' => $this->input->post('text'.$row['lang_id']),
                    );
	  $this->db->where('var_id',$var_id);
	  $this->db->where('lang_id',$row['lang_id']);
	  $this->db->update('varieties',$data);
	   }
     }
    $Q->free_result();    
	}
function updateRightCategory($id, $cat_id){
					$this->db->select('*');
		$this->db->from('languages');
		 $this->db->orderby("lang_id","asc");
	$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
      $data = array('name' => $this->input->post('name'.$row['lang_id']),
	  'order' => $this->input->post('order'.$row['lang_id']),
                    );
	  $this->db->where('right_cat_id',$cat_id);
	  $this->db->where('lang_id',$row['lang_id']);
	  $this->db->update('right_category',$data);
	   }
     }
    $Q->free_result();    
	}
function updateNew($id, $new_id){
					$this->db->select('*');
		$this->db->from('languages');
		 $this->db->orderby("lang_id","asc");
	$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
      $data = array('title' => $this->input->post('title'.$row['lang_id']),
	  'longdesc' => $this->input->post('description'.$row['lang_id']),
	  'order' => $this->input->post('order'.$row['lang_id'])
                    );
	  $this->db->where('new_id',$new_id);
	  $this->db->where('lang_id',$row['lang_id']);
	  $this->db->update('news',$data);
	   }
     }
    $Q->free_result();    
	}

 function getCategoriesbyLang($id, $ld){
    $data = array();
		$this->db->select('*');
		$this->db->from('category');
	  $this->db->where('cat_id',$id);
	  $this->db->where('lang_id',$ld);
		$this->db->limit(1);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();    
    return $data;    
 } 
 function getVarietiesbyLang($id, $ld){
    $data = array();
		$this->db->select('*');
		$this->db->from('varieties');
	  $this->db->where('var_id',$id);
	  $this->db->where('lang_id',$ld);
		$this->db->limit(1);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();    
    return $data;    
 } 
 function getRightCategoriesbyLang($id, $ld){
    $data = array();
		$this->db->select('*');
		$this->db->from('right_category');
	  $this->db->where('right_cat_id',$id);
	  $this->db->where('lang_id',$ld);
		$this->db->limit(1);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();    
    return $data;    
 } 
 	  function getNewsbyLang($id, $ld){
    $data = array();
		$this->db->select('*');
		$this->db->from('news');
	  $this->db->where('new_id',$id);
	  $this->db->where('lang_id',$ld);
		$this->db->limit(1);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();    
    return $data;    
 } 
function deleteCategory($id){
 	$this->db->where('cat_id', $id);
	$this->db->delete('category');	
 	$this->db->where('cat_id', $id);
	$this->db->delete('sub_category');	
	}
function deleteVariety($id){
 	$this->db->where('var_id', $id);
	$this->db->delete('varieties');	
	}
function deleteRightCategory($id){
 	$this->db->where('right_cat_id', $id);
	$this->db->delete('right_category');	
 	//$this->db->where('cat_id', $id);
	//$this->db->delete('sub_category');	
	}
function deletePage($id){
 	$this->db->where('id', $id);
	$this->db->delete('pages');	
	}
function deleteOrder($id){
 	$this->db->where('id', $id);
	$this->db->delete('orders');	
 	$this->db->where('order_id', $id);
	$this->db->delete('order_details');	
	}
function deleteNew($id){
 	$this->db->where('new_id', $id);
	$this->db->delete('news');	
	}
 function getCategory($id){
    $data = array();
		$this->db->select('*');
		$this->db->from('category');
		$this->db->where('id',id_clean($id));
		$this->db->limit(1);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();    
    return $data;    
 }
 function getCategoryName($id, $ld){
    $data = array();
		$this->db->select('*');
		$this->db->from('category');
		$this->db->where('cat_id',id_clean($id));
		$this->db->where('lang_id',$ld);
		$this->db->limit(1);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();    
    return $data;    
 }
  function getRightCategoryName($id, $ld){
    $data = array();
		$this->db->select('*');
		$this->db->from('right_category');
		$this->db->where('right_cat_id',id_clean($id));
		$this->db->where('lang_id',$ld);
		$this->db->limit(1);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();    
    return $data;    
 }
  	function checkProductOffers($id){
		$this->db->select('*');
 	    $this->db->from('products');
		$this->db->where('id',$id);
		$this->db->where('offers','Yes');
		$Q = $this->db->get();
      if ($Q->num_rows() > 0){
		$data = $Q->row_array();
		$exist=TRUE;
      }
	  else {
	  	$exist=FALSE;
	  }
      $Q->free_result();    
      return $exist;  		
	}
function updateProductOffers() {
		$this->db->select('*');
		$this->db->from('products');
		$Q5=$this->db->get();
     if ($Q5->num_rows() > 0){
       foreach ($Q5->result_array() as $row){
	$value = $this->input->post($row['id']);
	if ($value == TRUE) {
		$this->db->select('*');
 	    $this->db->from('products');
		$this->db->where('id',$row['id']);
		$this->db->where('offers','Yes');
		$Q = $this->db->get();
	    if ($Q->num_rows() > 0){
        $data_ch = true;
        } else {
		$data_ch = false;
		}
        $Q->free_result();    

	if ($data_ch==false) {
	$data = array( 
		'offers' => 'Yes',
		'offer_price' => $this->input->post('offer_price'.$row['id'])
		);
	$this->db->where('id', $row['id']);
	$this->db->update('products',$data);
	} elseif ($data_ch==true) {
	$data = array( 
		'offer_price' => $this->input->post('offer_price'.$row['id'])
		);
	$this->db->where('id', $row['id']);
	$this->db->update('products',$data);
	} 
	} elseif ($value== FALSE) {
		$data = array( 
		'offers' => 'No',
		'offer_price' => 0
		);
		$this->db->where('id', $row['id']);
		$this->db->update('products', $data);
	}
	}
    }
    $Q5->free_result();  
}
 function getProductCategories($p_id){
	    $data = array();
		$this->db->select('*');
		$this->db->from('product_categories');
		$this->db->where('p_id',id_clean($p_id));
		$Q=$this->db->get();
        if ($Q->num_rows() > 0){
        foreach ($Q->result_array() as $row){
        $data[] = $row;
       }
     }

    $Q->free_result();    
    return $data;    
 }
	function getProductCat($id){
		$ld=$this->session->userdata('lang_id');
	    $data = array();
		$this->db->select('*');
		$this->db->from('product_categories');
		$this->db->where('p_id',$id);
		$this->db->limit(1);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }

    $Q->free_result();    
    return $data;    
 }
 function getProducts(){
    $data = array();
		$this->db->select('*');
		$this->db->from('products');
		$this->db->join('product_details','products.id=product_details.p_id');
		$this->db->where('product_details.lang_id',1);
		$this->db->orderby("product_details.name","asc");
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
     }

    $Q->free_result();    
    return $data;    
 }
function deleteProduct($p_id){
 	$this->db->where('id', $p_id);
	$this->db->delete('products');
	
	$this->db->where('p_id', $p_id);
	$this->db->delete('product_details');
	$this->db->where('p_id', $p_id);
	$this->db->delete('product_categories');
	$this->db->where('p_id', $p_id);
	$this->db->delete('product_subcategories');
}
  function getProductCategoryName($p_id){
	    $data = array();
		$this->db->select('*');
		$this->db->from('product_categories');
		$this->db->join('category','category.cat_id=product_categories.cat_id');
		$this->db->where('category.lang_id',1);
		$this->db->where('product_categories.p_id',id_clean($p_id));
		$this->db->limit(1);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();    
    return $data;    
 }
function getCategories2(){
    $data = array();
		$this->db->select('*');
		$this->db->from('category');
	  $this->db->where('lang_id',1);
	 $this->db->orderby("cat_id","asc");
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
     }
    $Q->free_result();    
    return $data;    
 }
	function saveProduct(){
	date_default_timezone_set("Europe/Athens");
	$now = date("Y-m-d G:i:s");

      $data = array('price' => $this->input->post('price'),
					'keywords' => $this->input->post('keywords'),
					'weight' => $this->input->post('weight'),
					'published' => $this->input->post('published'),
					'available' => $this->input->post('available'),
					'date_added' => $now
                    );
	  $this->db->insert('products',$data);
     							$data2 = array();
								$Q5 = $this->db->query('SELECT LAST_INSERT_ID()');
								if ($Q5->num_rows() > 0){
								   $data2 = $Q5->row_array();
								}
								$Q5->free_result();
								$msg_id = $data2;

 $p_id=$msg_id['LAST_INSERT_ID()'];
		
		$this->db->select('*');
		$this->db->from('languages');
	 $this->db->orderby("lang_id","asc");
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
      $data = array('p_id' => $p_id,
					 'name' => $this->input->post('name'.$row['lang_id']),
					 'description' => $this->input->post('description'.$row['lang_id']),
					 'suggestions' => $this->input->post('suggestions'.$row['lang_id']),
					 'characteristics' => $this->input->post('characteristics'.$row['lang_id']),
					 'vinifications' => $this->input->post('vinification'.$row['lang_id']),
					 'microclimate' => $this->input->post('microclimate'.$row['lang_id']),
					 'other_characteristics' => $this->input->post('other_characteristics'.$row['lang_id']),
                    'lang_id' => $row['lang_id']
                    );
	  $this->db->insert('product_details',$data);
       }
     }
    $Q->free_result();
	
	 $this->db->select('*');
	 $this->db->from('category');
	 $this->db->where('lang_id',1);
	 $this->db->orderby("cat_id","asc");
		$Q5=$this->db->get();
     if ($Q5->num_rows() > 0){
       foreach ($Q5->result_array() as $row){
	$value = $this->input->post($row['cat_id']);
	if ($value == TRUE) {
	$data_category = array( 
		'p_id' => $p_id,
		'cat_id' => $row['cat_id']
		);
	$this->db->insert('product_categories',$data_category);
	}
	
	}
    }
    $Q5->free_result();  
    return $p_id;    
	}
	
 function getProduct($p_id){
    $data = array();
		$this->db->select('*');
		$this->db->from('products');
		$this->db->where('id',id_clean($p_id));
		$this->db->limit(1);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();    
    return $data;    
 }
function updateProduct($p_id){

      $data = array('price' => $this->input->post('price'),
					'published' => $this->input->post('published'),
					'available' => $this->input->post('available'),
					'keywords' => $this->input->post('keywords'),
					'weight' => $this->input->post('weight')
                    );
	  $this->db->where('id',$p_id);
	  $this->db->update('products',$data);
}
function getProductDetails($p_id){
    $data = array();
		$this->db->select('*');
		$this->db->from('product_details');
		$this->db->where('p_id',id_clean($p_id));
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
     }

    $Q->free_result();    
    return $data;    
 }
function updateProductDetails($id, $p_id){
      $data = array('name' => $this->input->post('name'),
					'description' => $this->input->post('description'),
					'suggestions' => $this->input->post('suggestions'),
					'characteristics' => $this->input->post('characteristics'),
					'vinifications' => $this->input->post('vinifications'),
					'microclimate' => $this->input->post('microclimate'),
					'other_characteristics' => $this->input->post('other_characteristics'),
					'lang_id' => $this->input->post('language')
                    );
	  $this->db->where('id',$id);
	  $this->db->update('product_details',$data);	
}
function updateProductCategory($p_id) {
	 $this->db->select('*');
	 $this->db->from('category');
	 $this->db->where('lang_id',1);
	 $this->db->orderby("cat_id","asc");
		$Q5=$this->db->get();
     if ($Q5->num_rows() > 0){
       foreach ($Q5->result_array() as $row){
	$value = $this->input->post($row['cat_id']);
	if ($value == TRUE) {
		$this->db->select('*');
 	    $this->db->from('product_categories');
		$this->db->where('p_id',$p_id);
		$this->db->where('cat_id',$row['cat_id']);
		$Q = $this->db->get();
	    if ($Q->num_rows() > 0){
        $data_ch = true;
        } else {
		$data_ch = false;
		}
        $Q->free_result();    

	if ($data_ch==false) {
	$data_category = array( 
		'p_id' => $p_id,
		'cat_id' => $row['cat_id']
		);
	$this->db->insert('product_categories',$data_category);
	}
	} elseif ($value== FALSE) {
		$this->db->where('p_id', $p_id);
		$this->db->where('cat_id', $row['cat_id']);
		$this->db->delete('product_categories');
	}
	}
    }
    $Q5->free_result();  
	
}
function checkProductCat($id, $c_id){
		$this->db->select('*');
 	    $this->db->from('product_categories');
		$this->db->where('p_id',$id);
		$this->db->where('cat_id',$c_id);
		$Q = $this->db->get();
      if ($Q->num_rows() > 0){
		$data = $Q->row_array();
		$exist=TRUE;
      }
	  else {
	  	$exist=FALSE;
	  }

      $Q->free_result();    
      return $exist;  		

	}
	
function getProductSubCategories($p_id){
	    $data = array();
		$this->db->select('*');
		$this->db->from('product_subcategories');
		$this->db->where('p_id',id_clean($p_id));
		$Q=$this->db->get();
        if ($Q->num_rows() > 0){
        foreach ($Q->result_array() as $row){
        $data[] = $row;
       }
     }

    $Q->free_result();    
    return $data;    
 }
function getProductSubSubCategories($p_id){
	    $data = array();
		$this->db->select('*');
		$this->db->from('product_subsubcategories');
		$this->db->where('p_id',id_clean($p_id));
		$Q=$this->db->get();
        if ($Q->num_rows() > 0){
        foreach ($Q->result_array() as $row){
        $data[] = $row;
       }
     }

    $Q->free_result();    
    return $data;    
 }
function updateProductSubCategory($p_id) {
	    $data = array();
		$this->db->select('*');
		$this->db->from('product_categories');
		$this->db->where('p_id',id_clean($p_id));
		$Q5=$this->db->get();
        if ($Q5->num_rows() > 0){
        foreach ($Q5->result_array() as $row){
		$this->db->select('*');
		$this->db->from('sub_category');
	 	$this->db->where('cat_id',$row['cat_id']);
	    $this->db->where('lang_id',1);
	    $this->db->orderby("s_id","asc");
		$Q2=$this->db->get();
     if ($Q2->num_rows() > 0){
       foreach ($Q2->result_array() as $row){
		$value2 = $this->input->post($row['sub_id']);
		 if ($value2 == TRUE) {
		$this->db->select('*');
 	    $this->db->from('product_subcategories');
		$this->db->where('p_id',$p_id);
		$this->db->where('subcat_id',$row['sub_id']);
		$Q = $this->db->get();
	    if ($Q->num_rows() > 0){
        $data_ch = true;
        } else {
		$data_ch = false;
		}
    $Q->free_result();    
	if ($data_ch==false) {
	$data_subcategory = array( 
		'p_id' => $p_id,
		'subcat_id' => $row['sub_id']
		);
	$this->db->insert('product_subcategories',$data_subcategory);
	}
	} elseif ($value2== FALSE) {
		$this->db->where('p_id', $p_id);
		$this->db->where('subcat_id', $row['sub_id']);
		$this->db->delete('product_subcategories');
	}
	
	}
    }
		}
		}
    $Q2->free_result();  
    $Q5->free_result();  
}
function updateProductSubSubCategory($p_id) {
	    $data = array();
		$this->db->select('*');
		$this->db->from('product_subcategories');
		$this->db->where('p_id',id_clean($p_id));
		$Q5=$this->db->get();
        if ($Q5->num_rows() > 0){
        foreach ($Q5->result_array() as $row){
		$this->db->select('*');
		$this->db->from('sub_sub_category');
	 	$this->db->where('sub_id',$row['subcat_id']);
	    $this->db->where('lang_id',1);
	    $this->db->orderby("s_s_id","asc");
		$Q2=$this->db->get();
     if ($Q2->num_rows() > 0){
       foreach ($Q2->result_array() as $row){
		$value2 = $this->input->post($row['sub_sub_id']);
		 if ($value2 == TRUE) {
		$this->db->select('*');
 	    $this->db->from('product_subsubcategories');
		$this->db->where('p_id',$p_id);
		$this->db->where('subsubcat_id',$row['sub_sub_id']);
		$Q = $this->db->get();
	    if ($Q->num_rows() > 0){
        $data_ch = true;
        } else {
		$data_ch = false;
		}
    $Q->free_result();    
	if ($data_ch==false) {
	$data_subcategory = array( 
		'p_id' => $p_id,
		'subsubcat_id' => $row['sub_sub_id']
		);
	$this->db->insert('product_subsubcategories',$data_subcategory);
	}
	} elseif ($value2== FALSE) {
		$this->db->where('p_id', $p_id);
		$this->db->where('subsubcat_id', $row['sub_sub_id']);
		$this->db->delete('product_subsubcategories');
	}
	
	}
    }
		}
		}
    $Q2->free_result();  
    $Q5->free_result();  
}
function getSubCategoriesforProduct($c_id){
    $data = array();
		$this->db->select('*');
		$this->db->from('sub_category');
	  $this->db->where('cat_id',$c_id);
	  $this->db->where('lang_id',1);
	 $this->db->orderby("s_id","asc");
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
     }
    $Q->free_result();    
    return $data;    
 }
function getSubSubCategoriesforProduct($c_id){
    $data = array();
		$this->db->select('*');
		$this->db->from('sub_sub_category');
	  $this->db->where('sub_id',$c_id);
	  $this->db->where('lang_id',1);
	 $this->db->orderby("s_s_id","asc");
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
     }
    $Q->free_result();    
    return $data;    
 }
function getRightSubCategories($c_id){
    $data = array();
		$this->db->select('*');
		$this->db->from('right_sub_cat');
	  $this->db->where('cat_id',$c_id);
	  $this->db->where('lang_id',1);
	  $this->db->where('status','active');
	 $this->db->orderby("s_id","asc");
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
     }
    $Q->free_result();    
    return $data;    
 }
 	function checkProductSubCat($id, $c_id){
		$this->db->select('*');
 	    $this->db->from('product_subcategories');
		$this->db->where('p_id',$id);
		$this->db->where('subcat_id',$c_id);
		$Q = $this->db->get();
      if ($Q->num_rows() > 0){
		$data = $Q->row_array();
		$exist=TRUE;
      }
	  else {
	  	$exist=FALSE;
	  }

      $Q->free_result();    
      return $exist;  		

	}
 	function checkProductSubSubCat($id, $c_id){
		$this->db->select('*');
 	    $this->db->from('product_subsubcategories');
		$this->db->where('p_id',$id);
		$this->db->where('subsubcat_id',$c_id);
		$Q = $this->db->get();
      if ($Q->num_rows() > 0){
		$data = $Q->row_array();
		$exist=TRUE;
      }
	  else {
	  	$exist=FALSE;
	  }

      $Q->free_result();    
      return $exist;  		

	}
 function getSubCategoryName($id, $ld){
    $data = array();
		$this->db->select('*');
		$this->db->from('sub_category');
		$this->db->where('sub_id',id_clean($id));
		$this->db->where('lang_id',$ld);
		$this->db->limit(1);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();    
    return $data;    
 }
  function getSubSubCategoryName($id, $ld){
    $data = array();
		$this->db->select('*');
		$this->db->from('sub_sub_category');
		$this->db->where('sub_sub_id',id_clean($id));
		$this->db->where('lang_id',$ld);
		$this->db->limit(1);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();    
    return $data;    
 }
 function RenamePhoto($filename, $append)
        {
            $imagename = substr($filename, 0, -4); // extract the image name
            $extension = substr($filename, -4); // extract the extension
            // Not all image extensions are created equal, we're expecting a 3 letter extension so if we get a .jpeg extension, let's convert it
            if($extension == "jpeg")
            {
                $imagename = substr($imagename, 0, -1);
                $extension = '.jpg';
            }
            $extension = strtolower($extension); // I like uniform lowercase file extensions
            $new_filename = $append.$extension; // put the filename string together
            return $new_filename;
        } 
function InsertPicture($new_name, $id){
	 $data = array( 
		'image' => $new_name
	);
 	$this->db->where('id', $id);
	$this->db->update('products', $data);
 }
 function getCompanyPhotos($cmp_id){
    $data = array();
		$this->db->select('*');
		$this->db->from('photo');
		$this->db->where('photo_cmp_id',$cmp_id);
		$this->db->orderby("photo_order","asc");
		//$this->db->join('hotel_details','hotels.h_id=hotel_details.h_id');
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
     }

    $Q->free_result();    
    return $data;    
 }
 function getCompanyPhotos2($cmp_id){
    $data = array();
		$this->db->select('*');
		$this->db->from('photo');
		$this->db->where('photo_id',$cmp_id);
		//$this->db->orderby("photo_order","asc");
		//$this->db->join('hotel_details','hotels.h_id=hotel_details.h_id');
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();    
    return $data;    
 }
 	function deletePhoto($photo_id){
	   $this->db->where('photo_id', $photo_id);
	   $this->db->delete('photo');
	}
function InsertPicturesMore($new_name, $p_id){
	date_default_timezone_set("Europe/Athens");
	$now = date("Y-m-d G:i:s");
	
	 $data = array( 
		'photo_p_id' => $p_id,
		'photo_image' => $new_name,
		'date_added' => $now
	);
	$this->db->insert('photo', $data);
 }

//  function getHotelDetailsUnique($h_id){
//    $data = array();
//		$this->db->select('*');
//		$this->db->from('hotel_details');
//		$this->db->where('h_id',id_clean($h_id));
//		$this->db->limit(1);
//		$Q=$this->db->get();
//		if ($Q->num_rows() > 0){
//      $data = $Q->row_array();
//    }
//
//    $Q->free_result();    
//    return $data;    
// }

function addSubCategory($id){
					$this->db->select('*');
		$this->db->from('languages');
		 $this->db->orderby("lang_id","asc");
	$Q=$this->db->get();
     if ($Q->num_rows() > 0){
		 $c=1;
       foreach ($Q->result_array() as $row){
		    if ($c==1) {
      $data = array('name' => $this->input->post('name'.$row['lang_id']),
				    'order' => $this->input->post('order'.$row['lang_id']),
				    'home_page' => $this->input->post('home_page'),
					'cat_id' => $id,
                    'lang_id' => $row['lang_id']
                    );
	  $this->db->insert('sub_category',$data);
		       					$data2 = array();
								$Q5 = $this->db->query('SELECT LAST_INSERT_ID()');
								if ($Q5->num_rows() > 0){
								   $data2 = $Q5->row_array();
								}
								$Q5->free_result();
								$cat_id = $data2;
					$c_id=$cat_id['LAST_INSERT_ID()'];
				    $data = array('sub_id' => $c_id
								  );
	  $this->db->where('s_id',$c_id);
	  $this->db->update('sub_category',$data);	
			} else {
				      $data = array('name' => $this->input->post('name'.$row['lang_id']),
					  'order' => $this->input->post('order'.$row['lang_id']),
				    'home_page' => $this->input->post('home_page'),
					'cat_id' => $id,
					 'sub_id' => $c_id,
                    'lang_id' => $row['lang_id']
                    );
	  $this->db->insert('sub_category',$data);
	         }
			 	  $c++;
	   }
     }
    $Q->free_result();    
	  }
function addSubSubCategory($id, $category_id){
					$this->db->select('*');
		$this->db->from('languages');
		 $this->db->orderby("lang_id","asc");
	$Q=$this->db->get();
     if ($Q->num_rows() > 0){
		 $c=1;
       foreach ($Q->result_array() as $row){
		    if ($c==1) {
      $data = array('name' => $this->input->post('name'.$row['lang_id']),
				    'order' => $this->input->post('order'.$row['lang_id']),
					 'home_page' => $this->input->post('home_page'),
					'cat_id' => $category_id,
 					'sub_id' => $id,
                   'lang_id' => $row['lang_id']
                    );
	  $this->db->insert('sub_sub_category',$data);
		       					$data2 = array();
								$Q5 = $this->db->query('SELECT LAST_INSERT_ID()');
								if ($Q5->num_rows() > 0){
								   $data2 = $Q5->row_array();
								}
								$Q5->free_result();
								$cat_id = $data2;
					$c_id=$cat_id['LAST_INSERT_ID()'];
				    $data = array('sub_sub_id' => $c_id
								  );
	  $this->db->where('s_s_id',$c_id);
	  $this->db->update('sub_sub_category',$data);	
			} else {
				      $data = array('name' => $this->input->post('name'.$row['lang_id']),
					  'order' => $this->input->post('order'.$row['lang_id']),
					   'home_page' => $this->input->post('home_page'),
					'cat_id' => $category_id,
 					'sub_id' => $id,
					 'sub_sub_id' => $c_id,
                    'lang_id' => $row['lang_id']
                    );
	  $this->db->insert('sub_sub_category',$data);
	         }
			 	  $c++;
	   }
     }
    $Q->free_result();    
	  }
function addRightSubCategory($id){
					$this->db->select('*');
		$this->db->from('languages');
		 $this->db->orderby("lang_id","asc");
	$Q=$this->db->get();
     if ($Q->num_rows() > 0){
		 $c=1;
       foreach ($Q->result_array() as $row){
		    if ($c==1) {
      $data = array('name' => $this->input->post('name'.$row['lang_id']),
	  				'title' => $this->input->post('title'.$row['lang_id']),
					'content' => $this->input->post('content'.$row['lang_id']),
				    'order' => $this->input->post('order'.$row['lang_id']),
					'cat_id' => $id,
                    'lang_id' => $row['lang_id']
                    );
	  $this->db->insert('right_sub_cat',$data);
		       					$data2 = array();
								$Q5 = $this->db->query('SELECT LAST_INSERT_ID()');
								if ($Q5->num_rows() > 0){
								   $data2 = $Q5->row_array();
								}
								$Q5->free_result();
								$cat_id = $data2;
					$c_id=$cat_id['LAST_INSERT_ID()'];
				    $data = array('sub_id' => $c_id
								  );
	  $this->db->where('s_id',$c_id);
	  $this->db->update('right_sub_cat',$data);	
			} else {
				      $data = array('name' => $this->input->post('name'.$row['lang_id']),
					  'title' => $this->input->post('title'.$row['lang_id']),
					'content' => $this->input->post('content'.$row['lang_id']),
					  'order' => $this->input->post('order'.$row['lang_id']),
					'cat_id' => $id,
					 'sub_id' => $c_id,
                    'lang_id' => $row['lang_id']
                    );
	  $this->db->insert('right_sub_cat',$data);
	         }
			 	  $c++;
	   }
     }
    $Q->free_result();    
	  }
function deleteSubCategory($s_id){
 	$this->db->where('sub_id', $s_id);
	$this->db->delete('sub_category');	
	}
function deleteSubSubCategory($s_id){
 	$this->db->where('sub_sub_id', $s_id);
	$this->db->delete('sub_sub_category');	
	}
function deleteRightSubCategory($s_id){
 	$this->db->where('sub_id', $s_id);
	$this->db->delete('right_sub_cat');	
	}

 function getSubCategories($id){
    $data = array();
		$this->db->select('*');
		$this->db->from('sub_category');
		$this->db->where('cat_id',id_clean($id));
		$this->db->groupby('sub_id');
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
     }

    $Q->free_result();    
    return $data;    
 }
 function getSubSubCategories($id){
    $data = array();
		$this->db->select('*');
		$this->db->from('sub_sub_category');
		$this->db->where('sub_id',id_clean($id));
		$this->db->groupby('sub_sub_id');
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
     }

    $Q->free_result();    
    return $data;    
 }
 	  function getSubCategoriesbyLang2($id, $ld){
    $data = array();
		$this->db->select('*');
		$this->db->from('sub_category');
	  $this->db->where('sub_id',$id);
	  $this->db->where('lang_id',$ld);
		$this->db->limit(1);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();    
    return $data;    
 } 
 	  function getSubSubCategoriesbyLang2($id, $ld){
    $data = array();
		$this->db->select('*');
		$this->db->from('sub_sub_category');
	  $this->db->where('sub_sub_id',$id);
	  $this->db->where('lang_id',$ld);
		$this->db->limit(1);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();    
    return $data;    
 } 
 	  function getRightSubCategoriesbyLang($id, $ld){
    $data = array();
		$this->db->select('*');
		$this->db->from('right_sub_cat');
	  $this->db->where('sub_id',$id);
	  $this->db->where('lang_id',$ld);
		$this->db->limit(1);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();    
    return $data;    
 } 
function updateSubCategory($s_id){
						$this->db->select('*');
		$this->db->from('languages');
		 $this->db->orderby("lang_id","asc");
	$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
      $data = array('name' => $this->input->post('name'.$row['lang_id']),
	  'order' => $this->input->post('order'.$row['lang_id']),
	    'home_page' => $this->input->post('home_page')
                    );
	  $this->db->where('sub_id',$s_id);
	  $this->db->where('lang_id',$row['lang_id']);
	  $this->db->update('sub_category',$data);
	   }
     }
    $Q->free_result();    
	}
function updateSubSubCategory($s_id){
						$this->db->select('*');
		$this->db->from('languages');
		 $this->db->orderby("lang_id","asc");
	$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
      $data = array('name' => $this->input->post('name'.$row['lang_id']),
	  'order' => $this->input->post('order'.$row['lang_id']),
	   'home_page' => $this->input->post('home_page')
                    );
	  $this->db->where('sub_sub_id',$s_id);
	  $this->db->where('lang_id',$row['lang_id']);
	  $this->db->update('sub_sub_category',$data);
	   }
     }
    $Q->free_result();    
	}
function updateRightSubCategory($s_id){
						$this->db->select('*');
		$this->db->from('languages');
		 $this->db->orderby("lang_id","asc");
	$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
      $data = array('name' => $this->input->post('name'.$row['lang_id']),
	  'title' => $this->input->post('title'.$row['lang_id']),
	  'content' => $this->input->post('content'.$row['lang_id']),
	  'order' => $this->input->post('order'.$row['lang_id']),
                    );
	  $this->db->where('sub_id',$s_id);
	  $this->db->where('lang_id',$row['lang_id']);
	  $this->db->update('right_sub_cat',$data);
	   }
     }
    $Q->free_result();    
	}
 function getProductPhotos($p_id){
    $data = array();
		$this->db->select('*');
		$this->db->from('photo');
		$this->db->where('photo_p_id',$p_id);
		$this->db->orderby("photo_order","asc");
		//$this->db->join('hotel_details','hotels.h_id=hotel_details.h_id');
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
     }

    $Q->free_result();    
    return $data;    
 }
 function getProductPhotos2($id){
    $data = array();
		$this->db->select('*');
		$this->db->from('photo');
		$this->db->where('photo_id',$id);
		//$this->db->orderby("photo_order","asc");
		//$this->db->join('hotel_details','hotels.h_id=hotel_details.h_id');
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();    
    return $data;    
 }













  function getSubCategory($id){
    $data = array();
		$this->db->select('*');
		$this->db->from('sub_category');
		$this->db->where('sub_id',id_clean($id));
		$this->db->limit(1);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();    
    return $data;    
 }

 function search($term){
		$data=array();
		$this->db->select("*");
		$this->db->from('products');
	    $this->db->join('product_details','products.id=product_details.p_id', 'left');
	    //$this->db->join('locations','hotels.h_loc=locations.location_id', 'left');
		$this->db->where('product_details.lang_id',1);
		//$this->db->where('published','Yes');
		$this->db->where("(product_details.name LIKE '%$term%')");
		//$this->db->where("(locations.location LIKE '%$term%')");
		$this->db->orderby('product_details.name','asc');	
		//$this->db->limit(50);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
			foreach ($Q->result_array() as $row){
				$data[] = $row;
			}
		}
		$Q->free_result();
		return $data;
}

function getHotels2(){
    $data = array();
		$this->db->select('*');
		$this->db->from('hotels');
		$this->db->orderby("h_id","asc");
		//$this->db->join('hotel_details','hotels.h_id=hotel_details.h_id');
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
     }

    $Q->free_result();    
    return $data;    
 }
 function getHotels_Details($h_id){
    $data = array();
		$this->db->select('*');
		$this->db->from('hotels');
		$this->db->join('hotel_details','hotels.h_id=hotel_details.h_id');
	    $this->db->where('hotel_details.lang_id', '1');
	    $this->db->where('hotels.h_id',$h_id);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();    
    return $data;    
 }
function getHotels_Details2(){
    $data = array();
		$this->db->select('*');
		$this->db->from('hotels');
		$this->db->join('hotel_details','hotels.h_id=hotel_details.h_id');
	    $this->db->where('hotel_details.lang_id', '1');
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
     }
    $Q->free_result();    
    return $data;    
 }
 
 function getHotelPhotos($h_id){
    $data = array();
		$this->db->select('*');
		$this->db->from('photo');
		$this->db->where('photo_h_id',$h_id);
		$this->db->orderby("photo_order","asc");
		//$this->db->join('hotel_details','hotels.h_id=hotel_details.h_id');
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
     }

    $Q->free_result();    
    return $data;    
 }
function getSlidePhotos2($id){
    $data = array();
		$this->db->select('*');
		$this->db->from('slideshow');
		$this->db->where('id',$id);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();    
    return $data;    
 }
	function deleteSlideshowPhoto($photo_id){
	   $this->db->where('id', $photo_id);
	   $this->db->delete('slideshow');
	}
	function getHotelPhoto($p_id){
    $data = array();
		$this->db->select('*');
		$this->db->from('photo');
		$this->db->where('photo_id',id_clean($p_id));
		$this->db->limit(1);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }

    $Q->free_result();    
    return $data;    
 }

 
 	  function getSubCategoriesbyLang($id, $ld){
    $data = array();
		$this->db->select('*');
		$this->db->from('sub_category');
	  $this->db->where('cat_id',$id);
	  $this->db->where('lang_id',$ld);
		$this->db->limit(1);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();    
    return $data;    
 }
function getTableInfo($id, $table, $param){
    $data = array();
		$this->db->select('*');
		$this->db->from($table);
		$this->db->where($param,id_clean($id));
		$this->db->where('lang_id','1');
		$this->db->limit(1);
		$Q=$this->db->get();
		if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }

    $Q->free_result();    
    return $data;    
 }
    function getTableFields($lang_id, $table_name){
     $data = array();
     $this->db->select('*');
	 if ($lang_id != ''){
	 $this->db->where('lang_id',$lang_id);
	 }
     $Q = $this->db->get($table_name);
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
    }
    $Q->free_result();  
    return $data; 
 }
    function getTableFieldsWhere($lang_id, $table_name, $where, $where_var){
     $data = array();
		$this->db->select('*');
		$this->db->from($table_name);
	 if ($lang_id != ''){
	 $this->db->where('lang_id',$lang_id);
	 }
	    $this->db->where($where, $where_var);
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
    }
    $Q->free_result();  
    return $data; 
 }
    function getTableFieldsWhere2($lang_id, $table_name, $where, $where_var){
     $data = array();
		$this->db->select('*');
		$this->db->from($table_name);
	 if ($lang_id != ''){
	 $this->db->where('lang_id',$lang_id);
	 }
	 		$this->db->orderby("location","asc");
	    $this->db->where($where, $where_var);
		$Q=$this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
    }
    $Q->free_result();  
    return $data; 
 }
function InsertSlidePicture($new_name){
	date_default_timezone_set("Europe/Athens");
	$now = date("Y-m-d G:i:s");
	
	 $data = array( 
		'photo_image' => $new_name
		);
	$this->db->insert('slideshow', $data);
	     						$data2 = array();
								$Q5 = $this->db->query('SELECT LAST_INSERT_ID()');
								if ($Q5->num_rows() > 0){
								   $data2 = $Q5->row_array();
								}
								$Q5->free_result();
								$msg_id = $data2;

 		$p_id=$msg_id['LAST_INSERT_ID()'];
		return $p_id;
 }
 function save_slide_details($photo_id){
	 $data = array( 
		'hotel_id' => $this->input->post('hotel'),
		'published' => $this->input->post('published')
	);
 	$this->db->where('id', $photo_id);
	$this->db->update('slideshow', $data);
 }






	function getUser($id){
      $data = array();
      $options = array('id' => $id);
      $Q = $this->db->getwhere('users',$options,1);
      if ($Q->num_rows() > 0){
        $data = $Q->row_array();
      }

      $Q->free_result();    
      return $data;  		

	}
	
	function getAllUsers(){
     $data = array();
	$this->db->where('username !=','getid');
     $Q = $this->db->get('users');
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
     }
     $Q->free_result();    
     return $data; 	
	}
	
	
	function addUser(){
      $data = array('username' => $this->input->post('username'),
                    'email' => $this->input->post('email'),
                    'status' => $this->input->post('status'),
                    'password' => md5($this->input->post('password'))
                    );
	
	  $this->db->insert('users',$data);
	
	}
	
	function updateUser(){
      $data = array('username' => $this->input->post('username'),
                    'email' => $this->input->post('email'),
                    'status' => $this->input->post('status'),
                    'password' => md5($this->input->post('password'))
                    );
	  $this->db->where('id',$this->input->post('id'));
	  $this->db->update('users',$data);	
	
	}
	
	
	function deleteUser($id){
 	 $data = array('status' => 'inactive');
 	 $this->db->where('id', $id);
	 $this->db->update('users', $data);
	
	}
	
	

	
}?>