<?php

class MDashboard extends Model{

	function MDashboard(){
		parent::Model();
	}


 function getCategories(){
     $data = array();
     //$this->db->where("category_id",$catid);
     //$this->db->where('status', 'published');
	//$this->db->orderby('pubdate', 'desc');
     $Q = $this->db->get('category');
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
    }
    $Q->free_result();  
    return $data; 
 }
	function getCategory($id) {
	      $data = array();
		  $this->db->select('*');
	 	  $this->db->from('category');
		  //$this->db->join('clients_details','client_category.id=clients_details.client_category_id', 'left');
	      $this->db->where('cat_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 updateProjectCategory(){
	$data = array( 
		'cat_name' => db_clean($_POST['name']),
		'cat_type' => db_clean($_POST['type'])
	);
 	$this->db->where('cat_id', id_clean($_POST['cat_id']));
	$this->db->update('category', $data);
	
 }
 function addProjectCategory(){
	$data = array( 
		'cat_name' => db_clean($_POST['name']),
		'cat_type' => db_clean($_POST['type'])
	);

	$this->db->insert('category', $data);	 
 }
   function getConDetails(){
     $data = array();
     //$this->db->where("category_id",$catid);
     //$this->db->where('status', 'published');
	//$this->db->orderby('pubdate', 'desc');
     $Q = $this->db->get('cnstrdetails');
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
    }
    $Q->free_result();  
    return $data; 
 }


 function getConDetail($id) {
	      $data = array();
		  $this->db->select('*');
	 	  $this->db->from('cnstrdetails');
		  //$this->db->join('clients_details','client_category.id=clients_details.client_category_id', 'left');
	      $this->db->where('cnstr_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 updateConDetails(){
	$data = array( 
		'cnstr_name' => db_clean($_POST['name'])
	);
 	$this->db->where('cnstr_id', id_clean($_POST['cnstr_id']));
	$this->db->update('cnstrdetails', $data);
	
 }
 
 function addConDetails(){
	$data = array( 
		'cnstr_name' => db_clean($_POST['name'])
	);

	$this->db->insert('cnstrdetails', $data);	 
 }
    function getArchitects(){
     $data = array();
     //$this->db->where("category_id",$catid);
     //$this->db->where('status', 'published');
	//$this->db->orderby('pubdate', 'desc');
     $Q = $this->db->get('design');
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
    }
    $Q->free_result();  
    return $data; 
 }
 function getArchitect($id) {
	      $data = array();
		  $this->db->select('*');
	 	  $this->db->from('design');
		  //$this->db->join('clients_details','client_category.id=clients_details.client_category_id', 'left');
	      $this->db->where('design_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 updateArchitect(){
  if ($this->input->post('language')=="Greek"){
			$lang_id = 1;
			}
	elseif ($this->input->post('language')=="English"){
			$lang_id = 2;
			}
	$data = array( 
		'lang_id' => $lang_id,
		'name' => db_clean($_POST['name'])
	);
 	$this->db->where('design_id', id_clean($_POST['design_id']));
	$this->db->update('design', $data);
	
 }
 
 function addArchitect(){
     if ($this->input->post('language')=="Greek"){
			$lang_id = 1;
			}
	elseif ($this->input->post('language')=="English"){
			$lang_id = 2;
			}
	$data = array( 
		'lang_id' => $lang_id,
		'name' => db_clean($_POST['name'])
	);
	$this->db->insert('design', $data);	 
 }
    function getStatusProjects(){
     $data = array();
     //$this->db->where("category_id",$catid);
     //$this->db->where('status', 'published');
	//$this->db->orderby('pubdate', 'desc');
     $Q = $this->db->get('status');
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
    }
    $Q->free_result();  
    return $data; 
 }
 function getStatusProject($id) {
	      $data = array();
		  $this->db->select('*');
	 	  $this->db->from('status');
		  //$this->db->join('clients_details','client_category.id=clients_details.client_category_id', 'left');
	      $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 updateStatusProject(){
  if ($this->input->post('language')=="Greek"){
			$lang_id = 1;
			}
	elseif ($this->input->post('language')=="English"){
			$lang_id = 2;
			}
	$data = array( 
		'status_id' => db_clean($_POST['status_id']),
		'lang_id' => $lang_id,
		'description' => db_clean($_POST['description'])
	);
 	$this->db->where('id', id_clean($_POST['id']));
	$this->db->update('status', $data);
	
 }
 
 function addStatusProject(){
     if ($this->input->post('language')=="Greek"){
			$lang_id = 1;
			}
	elseif ($this->input->post('language')=="English"){
			$lang_id = 2;
			}
	$data = array( 
		'status_id' => db_clean($_POST['status_id']),
		'lang_id' => $lang_id,
		'description' => db_clean($_POST['description'])
	);
	$this->db->insert('status', $data);	 
 }

    function getProjectsAddress(){
     $data = array();
     $this->db->select('prj_id, prj_address');
	 $this->db->where('lang_id','1');
     //$this->db->where('status', 'published');
	//$this->db->orderby('pubdate', 'desc');
     $Q = $this->db->get('project_details');
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
    }
    $Q->free_result();  
    return $data; 
 }
    function getProjectDetails($project_id){
	     if ($this->input->post('language')=="Greek"){
			$lang_id = 1;
			}
		elseif ($this->input->post('language')=="English"){
			$lang_id = 2;
			}

     $data = array();
     $this->db->select('*');
	 $this->db->where('prj_id',$project_id);
     $this->db->where('lang_id', $lang_id);
	//$this->db->orderby('pubdate', 'desc');
     $Q = $this->db->get('project_details');
     if ($Q->num_rows() > 0){
	       $data = $Q->row_array();

//       foreach ($Q->result_array() as $row){
//         $data[] = $row;
//       }
    }
    $Q->free_result();  
    return $data; 
 }
     function getProjectDetails2($project_id){
	 $ses_lang_id = $this->session->userdata('ses_lang_id');
     //$ses_lang_id = '1';
	 $data = array();
     $this->db->select('*');
	 $this->db->where('prj_id',$project_id);
     $this->db->where('lang_id', $ses_lang_id);
	//$this->db->orderby('pubdate', 'desc');
     $Q = $this->db->get('project_details');
     if ($Q->num_rows() > 0){
	       $data = $Q->row_array();

//       foreach ($Q->result_array() as $row){
//         $data[] = $row;
//       }
    }
    $Q->free_result();  
    return $data; 
 }
      function getlang_details($lang_id, $table_name, $field1_name, $field2_name, $field_need){
	 $data = array();
     $this->db->select($field_need);
	 $this->db->where($field1_name,$field2_name);
	 if ($lang_id != ''){ 
     $this->db->where('lang_id', $lang_id);
	 }
     $Q = $this->db->get($table_name);
     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 getProjectInfo($project_id){
     $data = array();
     $this->db->select('*');
	 $this->db->where('prj_id',$project_id);
     //$this->db->where('status', 'published');
	//$this->db->orderby('pubdate', 'desc');
     $Q = $this->db->get('project');
     if ($Q->num_rows() > 0){
	       $data = $Q->row_array();

//       foreach ($Q->result_array() as $row){
//         $data[] = $row;
//       }
    }
    $Q->free_result();  
    return $data; 
 }
function updateProject(){
	 $ses_lang_id = $this->session->userdata('ses_lang_id');
// $date = Now();
// $temp_date = explode("/",$date);
// $stamp = mktime(0,0,0,$temp_date[1],$temp_date[0],$temp_date[2]);
// $new_date = date('Y/m/d',$stamp);

//  if ($this->input->post('sold')=="Yes"){
//			$sold = 'Y';
//			}
//	elseif ($this->input->post('sold')=="No"){
//			$sold = 'N';
//			}
	$data_info = array( 
		'prj_cnstrStart' => db_clean($_POST['start_date']),
		'prj_cnstrFinish' => db_clean($_POST['finish_date']),
		'prj_category' => $this->input->post('category'),
		'prj_status' => $this->input->post('status'),
		'prj_thumbnail' => db_clean($_POST['thumbnail']),
		'prj_image' => db_clean($_POST['image']),
		'prj_sold' => $this->input->post('sold')
		//'date_added' => $new_date
		
	);
 	$this->db->where('prj_id', id_clean($_POST['project_id']));
	$this->db->update('project', $data_info);
	
	$data_details = array( 
		'prj_location' => $this->input->post('location'),
		'prj_address' => db_clean($_POST['address']),
		'prj_details' => db_clean($_POST['details']),
		'prj_area' => db_clean($_POST['area']),
		'prj_design' => $this->input->post('design')
		
	);
 	$this->db->where('prj_id', id_clean($_POST['project_id']));
 	$this->db->where('lang_id', $ses_lang_id);
	$this->db->update('project_details', $data_details);

 }

 function addProject(){
 // $date = Now();
// $temp_date = explode("/",$date);
// $stamp = mktime(0,0,0,$temp_date[1],$temp_date[0],$temp_date[2]);
// $new_date = date('Y/m/d',$stamp);

//  if ($this->input->post('sold')=="Yes"){
//			$sold = 'Y';
//			}
//	elseif ($this->input->post('sold')=="No"){
//			$sold = 'N';
//			}

	$data_info = array( 
		'prj_cnstrStart' => db_clean($_POST['start_date']),
		'prj_cnstrFinish' => db_clean($_POST['finish_date']),
		'prj_category' => $this->input->post('category'),
		'prj_status' => $this->input->post('status'),
		'prj_thumbnail' => db_clean($_POST['thumbnail']),
		'prj_image' => db_clean($_POST['image']),
		'prj_sold' => $this->input->post('sold')
		//'date_added' => $new_date
	);
	$this->db->insert('project', $data_info);
								$data = array();
								$Q5 = $this->db->query('SELECT LAST_INSERT_ID()');
								if ($Q5->num_rows() > 0){
								   $data = $Q5->row_array();
								}
								$Q5->free_result();
								$prj_id = $data;
	 	$data_details_gr = array( 
		'prj_id' => $prj_id['LAST_INSERT_ID()'],
		'lang_id' => '1',
		'prj_location' => $this->input->post('location_gr'),
		'prj_address' => db_clean($_POST['address_gr']),
		'prj_details' => db_clean($_POST['details_gr']),
		'prj_area' => db_clean($_POST['area_gr']),
		'prj_design' => $this->input->post('design_gr')
		//date_added' => $new_date
	);
		$this->db->insert('project_details', $data_details_gr);	
	 	
		$data_details_en = array( 
		'prj_id' => $prj_id['LAST_INSERT_ID()'],
		'lang_id' => '2',
		'prj_location' => $this->input->post('location_en'),
		'prj_address' => db_clean($_POST['address_en']),
		'prj_details' => db_clean($_POST['details_en']),
		'prj_area' => db_clean($_POST['area_en']),
		'prj_design' => $this->input->post('design_en')
		//date_added' => $new_date
	);
		$this->db->insert('project_details', $data_details_en);	
 }
    function getPhotoDetails($photo_id){
//	     if ($this->input->post('language')=="Greek"){
//			$lang_id = 1;
//			}
//		elseif ($this->input->post('language')=="English"){
//			$lang_id = 2;
//			}

     $data = array();
     $this->db->select('*');
	 $this->db->where('photo_id',$photo_id);
     //$this->db->where('lang_id', $lang_id);
	//$this->db->orderby('pubdate', 'desc');
     $Q = $this->db->get('photo_description');
     if ($Q->num_rows() > 0){
//	       $data = $Q->row_array();

       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
    }
    $Q->free_result();  
    return $data; 
 }
    function getProjectPhoto($project_id){
     $data = array();
     $this->db->select('*');
	 $this->db->where('photo_prjId',$project_id);
	 //$this->db->where('published','Yes');
     //$this->db->where('status', 'published');
	//$this->db->orderby('pubdate', 'desc');
     $Q = $this->db->get('photo');
     if ($Q->num_rows() > 0){
//	       $data = $Q->row_array();

       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
    }
    $Q->free_result();  
    return $data; 
 }
    function getPhoto($photo_id){
     $data = array();
     $this->db->select('*');
	 $this->db->where('photo_id',$photo_id);
     //$this->db->where('status', 'published');
	//$this->db->orderby('pubdate', 'desc');
     $Q = $this->db->get('photo');
     if ($Q->num_rows() > 0){
	       $data = $Q->row_array();

//       foreach ($Q->result_array() as $row){
//         $data[] = $row;
//       }
    }
    $Q->free_result();  
    return $data; 
 }
function updatePhoto(){
// $date = Now();
// $temp_date = explode("/",$date);
// $stamp = mktime(0,0,0,$temp_date[1],$temp_date[0],$temp_date[2]);
// $new_date = date('Y/m/d',$stamp);

//  if ($this->input->post('sold')=="Yes"){
//			$sold = 'Y';
//			}
//	elseif ($this->input->post('sold')=="No"){
//			$sold = 'N';
//			}
	$data_info = array( 
		'photo_prjId' => db_clean($_POST['photo_prjId']),
		'photo_image' => db_clean($_POST['photo_image']),
		'photo_thumb' => db_clean($_POST['photo_thumb']),
		'photo_order' => db_clean($_POST['photo_order']),
		'published' => $this->input->post('published'),
		//'date_added' => $new_date
	);
 	$this->db->where('photo_id', id_clean($_POST['photo_id']));
	$this->db->update('photo', $data_info);
	if ($_POST['lang']=='both'){
	$data_details_gr = array(
		'description' => $this->input->post('description_gr')
	);
 	$this->db->where('lang_id', '1');
 	$this->db->where('photo_id', id_clean($_POST['photo_id']));
	$this->db->update('photo_description', $data_details_gr);
	
	$data_details_en = array(
		'description' => $this->input->post('description_en')
	);
 	$this->db->where('lang_id', '2');
 	$this->db->where('photo_id', id_clean($_POST['photo_id']));
	$this->db->update('photo_description', $data_details_en);
	}
	elseif ($_POST['lang']=='en'){
		$data_details_gr = array(
		'photo_id' => id_clean($_POST['photo_id']),
		'description' => $this->input->post('description_gr'),
		'lang_id' => '1'
	);
 	//$this->db->where('photo_id', id_clean($_POST['photo_id']));
	$this->db->insert('photo_description', $data_details_gr);
	
	$data_details_en = array(
		'description' => $this->input->post('description_en')
	);
 	$this->db->where('lang_id', '2');
 	$this->db->where('photo_id', id_clean($_POST['photo_id']));
	$this->db->update('photo_description', $data_details_en);
	}
	elseif ($_POST['lang']=='gr'){
		$data_details_gr = array(
		'description' => $this->input->post('description_gr')
	);
 	$this->db->where('lang_id', '1');
 	$this->db->where('photo_id', id_clean($_POST['photo_id']));
	$this->db->update('photo_description', $data_details_gr);
	
	$data_details_en = array(
		'photo_id' => id_clean($_POST['photo_id']),
		'description' => $this->input->post('description_en'),
		'lang_id' => '2'
	);
 	//$this->db->where('photo_id', id_clean($_POST['photo_id']));
	$this->db->insert('photo_description', $data_details_en);
	}
	elseif ($_POST['lang']=='none'){
		$data_details_gr = array(
		'photo_id' => id_clean($_POST['photo_id']),
		'description' => $this->input->post('description_gr'),
		'lang_id' => '1'
	);
 	//$this->db->where('photo_id', id_clean($_POST['photo_id']));
	$this->db->insert('photo_description', $data_details_gr);
	
	$data_details_en = array(
		'photo_id' => id_clean($_POST['photo_id']),
		'description' => $this->input->post('description_en'),
		'lang_id' => '2'
	);
 	//$this->db->where('photo_id', id_clean($_POST['photo_id']));
	$this->db->insert('photo_description', $data_details_en);
	}
 }

 function addPhoto($prj_id){
 // $date = Now();
// $temp_date = explode("/",$date);
// $stamp = mktime(0,0,0,$temp_date[1],$temp_date[0],$temp_date[2]);
// $new_date = date('Y/m/d',$stamp);

//  if ($this->input->post('sold')=="Yes"){
//			$sold = 'Y';
//			}
//	elseif ($this->input->post('sold')=="No"){
//			$sold = 'N';
//			}

	$data_info = array( 
		'photo_prjID' => $prj_id,
		'photo_image' => db_clean($_POST['photo_image']),
		'photo_thumb' => db_clean($_POST['photo_thumb']),
		'photo_order' => db_clean($_POST['photo_order']),
		'published' => $this->input->post('published')
		//'date_added' => $new_date
	);
	$this->db->insert('photo', $data_info);
								$data = array();
								$Q5 = $this->db->query('SELECT LAST_INSERT_ID()');
								if ($Q5->num_rows() > 0){
								   $data = $Q5->row_array();
								}
								$Q5->free_result();
								$photo_id = $data;
								
	 	$data_details_gr = array( 
		'photo_id' => $photo_id['LAST_INSERT_ID()'],
		'lang_id' => '1',
		'description' => db_clean($_POST['description_gr'])
		);
		$this->db->insert('photo_description', $data_details_gr);	
	 	
	 	$data_details_en = array( 
		'photo_id' => $photo_id['LAST_INSERT_ID()'],
		'lang_id' => '2',
		'description' => db_clean($_POST['description_en'])
		);
		$this->db->insert('photo_description', $data_details_en);	
 }
    function getConDetailsCategories(){
     $data = array();
     $this->db->select('cnstr_id, cnstr_name');
	 //$this->db->where('lang_id','1');
     //$this->db->where('status', 'published');
	 //$this->db->orderby('pubdate', 'desc');
     $Q = $this->db->get('cnstrdetails');
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
    }
    $Q->free_result();  
    return $data; 
 }
    function getConDetailsPhotos($cnstr_id){
     $data = array();
     $this->db->select('*');
	 $this->db->where('photo_cnstr',$cnstr_id);
	 //$this->db->where('published','Yes');
     //$this->db->where('status', 'published');
	//$this->db->orderby('pubdate', 'desc');
     $Q = $this->db->get('photo');
     if ($Q->num_rows() > 0){
//	       $data = $Q->row_array();

       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
    }
    $Q->free_result();  
    return $data; 
 }
function updateCnstrPhoto(){
// $date = Now();
// $temp_date = explode("/",$date);
// $stamp = mktime(0,0,0,$temp_date[1],$temp_date[0],$temp_date[2]);
// $new_date = date('Y/m/d',$stamp);

//  if ($this->input->post('sold')=="Yes"){
//			$sold = 'Y';
//			}
//	elseif ($this->input->post('sold')=="No"){
//			$sold = 'N';
//			}
	$data_info = array( 
		'photo_cnstr' => db_clean($_POST['photo_cnstr']),
		'photo_image' => db_clean($_POST['photo_image']),
		'photo_thumb' => db_clean($_POST['photo_thumb']),
		'photo_order' => db_clean($_POST['photo_order']),
		'published' => $this->input->post('published'),
		//'date_added' => $new_date
	);
 	$this->db->where('photo_id', id_clean($_POST['photo_id']));
	$this->db->update('photo', $data_info);
	if ($_POST['lang']=='both'){
	$data_details_gr = array(
		'description' => $this->input->post('description_gr')
	);
 	$this->db->where('lang_id', '1');
 	$this->db->where('photo_id', id_clean($_POST['photo_id']));
	$this->db->update('photo_description', $data_details_gr);
	
	$data_details_en = array(
		'description' => $this->input->post('description_en')
	);
 	$this->db->where('lang_id', '2');
 	$this->db->where('photo_id', id_clean($_POST['photo_id']));
	$this->db->update('photo_description', $data_details_en);
	}
	elseif ($_POST['lang']=='en'){
		$data_details_gr = array(
		'photo_id' => id_clean($_POST['photo_id']),
		'description' => $this->input->post('description_gr'),
		'lang_id' => '1'
	);
 	//$this->db->where('photo_id', id_clean($_POST['photo_id']));
	$this->db->insert('photo_description', $data_details_gr);
	
	$data_details_en = array(
		'description' => $this->input->post('description_en')
	);
 	$this->db->where('lang_id', '2');
 	$this->db->where('photo_id', id_clean($_POST['photo_id']));
	$this->db->update('photo_description', $data_details_en);
	}
	elseif ($_POST['lang']=='gr'){
		$data_details_gr = array(
		'description' => $this->input->post('description_gr')
	);
 	$this->db->where('lang_id', '1');
 	$this->db->where('photo_id', id_clean($_POST['photo_id']));
	$this->db->update('photo_description', $data_details_gr);
	
	$data_details_en = array(
		'photo_id' => id_clean($_POST['photo_id']),
		'description' => $this->input->post('description_en'),
		'lang_id' => '2'
	);
 	//$this->db->where('photo_id', id_clean($_POST['photo_id']));
	$this->db->insert('photo_description', $data_details_en);
	}
	elseif ($_POST['lang']=='none'){
		$data_details_gr = array(
		'photo_id' => id_clean($_POST['photo_id']),
		'description' => $this->input->post('description_gr'),
		'lang_id' => '1'
	);
 	//$this->db->where('photo_id', id_clean($_POST['photo_id']));
	$this->db->insert('photo_description', $data_details_gr);
	
	$data_details_en = array(
		'photo_id' => id_clean($_POST['photo_id']),
		'description' => $this->input->post('description_en'),
		'lang_id' => '2'
	);
 	//$this->db->where('photo_id', id_clean($_POST['photo_id']));
	$this->db->insert('photo_description', $data_details_en);
	}
 }
 function addCnstrPhoto($cnstr_id){
 // $date = Now();
// $temp_date = explode("/",$date);
// $stamp = mktime(0,0,0,$temp_date[1],$temp_date[0],$temp_date[2]);
// $new_date = date('Y/m/d',$stamp);

//  if ($this->input->post('sold')=="Yes"){
//			$sold = 'Y';
//			}
//	elseif ($this->input->post('sold')=="No"){
//			$sold = 'N';
//			}

	$data_info = array( 
		'photo_cnstr' => $cnstr_id,
		'photo_image' => db_clean($_POST['photo_image']),
		'photo_thumb' => db_clean($_POST['photo_thumb']),
		'photo_order' => db_clean($_POST['photo_order']),
		'published' => $this->input->post('published')
		//'date_added' => $new_date
	);
	$this->db->insert('photo', $data_info);
								$data = array();
								$Q5 = $this->db->query('SELECT LAST_INSERT_ID()');
								if ($Q5->num_rows() > 0){
								   $data = $Q5->row_array();
								}
								$Q5->free_result();
								$photo_id = $data;
								
	 	$data_details_gr = array( 
		'photo_id' => $photo_id['LAST_INSERT_ID()'],
		'lang_id' => '1',
		'description' => db_clean($_POST['description_gr'])
		);
		$this->db->insert('photo_description', $data_details_gr);	
	 	
	 	$data_details_en = array( 
		'photo_id' => $photo_id['LAST_INSERT_ID()'],
		'lang_id' => '2',
		'description' => db_clean($_POST['description_en'])
		);
		$this->db->insert('photo_description', $data_details_en);	
 }












 function getPageName($id){
     $data = array();
     $this->db->where("id",$id);
     $Q = $this->db->get('categories');
    if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();  
    return $data; 
 }
 

 function getAllPostsbyCategory($catid){
     $data = array();
     $this->db->where("category_id",$catid);
     //$this->db->where('status', 'published');
	$this->db->orderby('pubdate', 'desc');
     $Q = $this->db->get('posts');
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
    }
    $Q->free_result();  
    return $data; 
 }

function getPost($id){
    $data = array();
    $this->db->where("id",$id);
    $this->db->limit(1);
    $Q = $this->db->get('posts');
    if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }

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

 function updatePost(){
 $date = $this->input->post('date');
 
 //$date = "22/03/2007";
$temp_date = explode("/",$date);
$stamp = mktime(0,0,0,$temp_date[1],$temp_date[0],$temp_date[2]);
$new_date = date('Y/m/d',$stamp);
//$check=(checkdate(12, 31, 2000));
//echo $new_date;
//if ($check==true){
	$data = array( 
		'title' => $this->input->post('title'),
		'status' => $this->input->post('status'),
		'body' => $this->input->post('body'),
		'category_id' => $this->input->post('category_id'),
		'pubdate' => $new_date,
		'user_id' => $_SESSION['userid']

	);

 	$this->db->where('id', $this->input->post('id'));
	$this->db->update('posts', $data);
	//}	
 
 }
 function addPost(){
  $date = $this->input->post('date');
 $temp_date = explode("/",$date);
$stamp = mktime(0,0,0,$temp_date[1],$temp_date[0],$temp_date[2]);
$new_date = date('Y/m/d',$stamp);

// 	$now = date("Y-m-d H:i:s");
	$data = array( 
		'title' => $this->input->post('title'),
		'tags' => $this->input->post('tags'),
		'status' => $this->input->post('status'),
		'body' => $this->input->post('body'),
		'category_id' => $this->input->post('category_id'),
		'user_id' => $_SESSION['userid'],
		'pubdate' => $new_date
	
	);

	$this->db->insert('posts', $data);	 
 }
 
 function deletePost($id){
 	$this->db->where('id', $id);
	$this->db->delete('posts');	
 }

 function getPageID($path){
     $data = array();
     $this->db->where("path",$path);
     $Q = $this->db->get('pages');
    if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();  
    return $data; 
 }
 function getAllPagesByID($page_id){
     $data = array();
     $this->db->where("id",$page_id);
     //$this->db->where('status', 'active');
	 $Q = $this->db->get('pages');
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
    }
    $Q->free_result();  
    return $data; 
 }
 function updatePage(){
	$data = array( 
		'name' => $this->input->post('name'),
		'status' => $this->input->post('status'),
		'content' => $this->input->post('content')
		);

 	$this->db->where('id', $this->input->post('id'));
	$this->db->update('pages', $data);	
 
 }

 function getPagePath($id){
     $data = array();
     $this->db->where("id",$id);
     $Q = $this->db->get('pages');
    if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();  
    return $data; 
 }

function getPage($id){
    $data = array();
    $this->db->where("id",$id);
    $this->db->limit(1);
    $Q = $this->db->get('pages');
    if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }

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







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

  function getLivePosts($limit){
     $data = array();
     $this->db->limit($limit);
     $this->db->where('status', 'published');
	$this->db->where('category_id',1);
     $this->db->order_by('pubdate','desc');
     $Q = $this->db->get('posts');
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
    }
    $Q->free_result();  
    return $data; 
 }
 
	function getAllLivePosts(){
     $data = array();
     $this->db->where('status', 'published');
	 $this->db->where('category_id',1);
     $this->db->order_by('pubdate','desc');
     $Q = $this->db->get('posts');
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
    }
    $Q->free_result();  
    return $data; 
 }
  
 
	
}

?>