<?php

class MDashboard extends Model{

	function MDashboars(){
	    parent::Controller();
		//session_start();

	  }

function getPage($id){
    $data = array();
    $this->db->where('id',id_clean($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 getPagePath($title_id){
    $data = array();
		$this->db->select('*');
		$this->db->from('pages');
		$this->db->join('pages_title','pages.id=pages_title.page_id', 'left');
		$this->db->where('pages_title.title_id',id_clean($title_id));
    $Q = $this->db->get();
    if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }

    $Q->free_result();    
    return $data;    
 }
  function getPagePathSection($section_id){
    $data = array();
		$this->db->select('*');
		$this->db->from('pages');
		$this->db->join('pages_details','pages.id=pages_details.page_id', 'left');
		$this->db->where('pages_details.section_id',id_clean($section_id));
    $Q = $this->db->get();
    if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }

    $Q->free_result();    
    return $data;    
 }
   function getPagePathCategory($cat_id){
    $data = array();
		$this->db->select('*');
		$this->db->from('pages');
		$this->db->join('categories_title','pages.id=categories_title.page_id', 'left');
		$this->db->where('categories_title.cat_id =',id_clean($cat_id));
    $Q = $this->db->get();
    if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }

    $Q->free_result();    
    return $data;    
 }
    function getPagePathCategory_page_id($page_id){
    $data = array();
		$this->db->select('*');
		$this->db->from('pages');
		$this->db->join('categories_title','pages.id=categories_title.page_id', 'left');
		$this->db->where('categories_title.page_id',id_clean($page_id));
    $Q = $this->db->get();
    if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }

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


   function getPagePathPageID($page_id){
    $data = array();
		$this->db->select('*');
		$this->db->from('pages');
		$this->db->join('pages_title','pages.id=pages_title.page_id', 'left');
		$this->db->where('pages_title.page_id',id_clean($page_id));
    $Q = $this->db->get();
    if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }

    $Q->free_result();    
    return $data;    
 }
 
   function getPageIDSection($section_id){
    $data = array();
		$this->db->select('*');
		$this->db->from('pages');
		$this->db->join('pages_details','pages.id=pages_details.page_id', 'left');
		$this->db->where('pages_details.section_id',id_clean($section_id));
    $Q = $this->db->get();
    if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }

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

 function getTitle($page_id){
     $data = array();
	 $this->db->select('*');
	 $this->db->from('pages');
	 $this->db->join('pages_title','pages.id=pages_title.page_id', 'left');
	 $this->db->where('id',$page_id);
     $Q = $this->db->get();
     if ($Q->num_rows() > 0){
      foreach ($Q->result_array() as $row){
	$data[] = $row;
			}
       }
    $Q->free_result();  
    return $data; 
}
 function getCodes(){
     $data = array();
	 $this->db->select('*');
	 $this->db->from('codes');
	 $Q = $this->db->get();
     if ($Q->num_rows() > 0){
      foreach ($Q->result_array() as $row){
	$data[] = $row;
			}
       }
    $Q->free_result();  
    return $data; 
}
	  function getCode($id) {
	      $data = array();
		  $this->db->select('*');
	 	  $this->db->from('codes');
		  $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 updateCode(){
	$data = array( 
		'name' => db_clean($_POST['name']),
		'code' => db_clean($_POST['code'])
	);
 	$this->db->where('id', id_clean($_POST['code_id']));
	$this->db->update('codes', $data);	
 
 }

 function getPageContent($id) {
 	$data = array();
	$this->db->select('*');
	$this->db->from('pages_details');
	$this->db->where('page_id',$id);
	$this->db->orderby('order','asc');
	$Q = $this->db->get();
	if ($Q->num_rows() > 0){
	foreach ($Q->result_array() as $row){
	$data[] = $row;
			}
		}
		$Q->free_result();
		return $data;
 }
 function getPage_Title($title_id){
     $data = array();
	 $this->db->select('*');
	 $this->db->from('pages_title');
     //$this->db->join('pages_title','pages.id=pages_title.page_id', 'left');
	 $this->db->where('title_id',id_clean($title_id));
//     $this->db->limit(1);
     $Q = $this->db->get();
     if ($Q->num_rows() > 0){
      $data = $Q->row_array();
       }
    $Q->free_result();  
    return $data; 
}
 function getPage_Section($section_id){
     $data = array();
	 $this->db->select('*');
	 $this->db->from('pages_details');
     //$this->db->join('pages_title','pages.id=pages_title.page_id', 'left');
	 $this->db->where('section_id',id_clean($section_id));
//     $this->db->limit(1);
     $Q = $this->db->get();
     if ($Q->num_rows() > 0){
      $data = $Q->row_array();
       }
    $Q->free_result();  
    return $data; 
}


 function getPageid ($path){
    $data = array();
    $this->db->where('path',$path);
    $this->db->where('status','active');
    $this->db->limit(1);
    $Q = $this->db->get('pages');
    if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }

    $Q->free_result();    
    return $data;    
 }
 function getAllContent($id, $ld) {
 	$data = array();
	$this->db->select('*');
	$this->db->from('pages_details');
	$this->db->where('page_id',$id);
	$this->db->where('lang_id',$ld);
	$Q = $this->db->get();
	if ($Q->num_rows() > 0){
	foreach ($Q->result_array() as $row){
	$data[] = $row;
			}
		}
		$Q->free_result();
		return $data;
 }
 function getPageTitle($id, $ld) {
 	$data = array();
	$this->db->select('*');
	$this->db->from('pages_title');
	$this->db->where('page_id',$id);
	$this->db->where('lang_id',$ld);
	$Q = $this->db->get();
	if ($Q->num_rows() > 0){
	foreach ($Q->result_array() as $row){
	$data[] = $row;
			}
		}
		$Q->free_result();
		return $data;
 }
  function getCurrentProjectsTitle($id) {
 	$data = array();
	$this->db->select('*');
	$this->db->from('categories_title');
	$this->db->where('page_id',$id);
	$Q = $this->db->get();
	if ($Q->num_rows() > 0){
	foreach ($Q->result_array() as $row){
	$data[] = $row;
			}
		}
		$Q->free_result();
		return $data;
 }
   function getCurrentProject($cat_id) {
 	$data = array();
	$this->db->select('*');
	$this->db->from('categories_title');
	$this->db->where('cat_id',$cat_id);
	$Q = $this->db->get();
	if ($Q->num_rows() > 0){
	  $data = $Q->row_array();
		}
		$Q->free_result();
		return $data;
 }

 
  function getAllClientsCategory() {
 		$data = array();
		$this->db->select('*');
		$this->db->from('client_category');
		$this->db->join('clients_details','client_category.id=clients_details.client_category_id', 'left');
		//$this->db->where('lang_id',$ld);
		$Q = $this->db->get();
		if ($Q->num_rows() > 0){
			foreach ($Q->result_array() as $row){
				$data[] = $row;
			}
		}
		$Q->free_result();
		return $data;
	}
	  function getClientsCategory($id) {
	      $data = array();
		  $this->db->select('*');
	 	  $this->db->from('client_category');
		  $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 getPrjTitle($id, $ld) {
 	$data = array();
	$this->db->select('*');
	$this->db->from('categories_title');
	$this->db->where('page_id',$id);
	$this->db->where('lang_id',$ld);
	$Q = $this->db->get();
	if ($Q->num_rows() > 0){
	foreach ($Q->result_array() as $row){
	$data[] = $row;
			}
		}
		$Q->free_result();
		return $data;
 }



	
 function getAllPages(){
     $data = array();
     $Q = $this->db->get('pages');
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
    }
    $Q->free_result();  
    return $data; 
 }
  function getAllPagesData(){
     $data = array();
	 $this->db->select('*');
	 $this->db->from('pages');
     $this->db->join('pages_title','pages.id=pages_title.page_id', 'left');
     //$this->db->join('pages_details','pages.id=pages_details.page_id', 'left');
     $Q = $this->db->get();
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
    }
    $Q->free_result();  
    return $data; 
 }


	
 function addPage(){
	$data = array( 
		'name' => db_clean($_POST['name']),
		'keywords' => db_clean($_POST['keywords']),
		'description' => db_clean($_POST['description']),
		'status' => db_clean($_POST['status'],8),
		'path' => db_clean($_POST['path']),
		'content' => $_POST['content']
	);

	$this->db->insert('pages', $data);	 
 }
 function addCode(){
	$data = array( 
		'name' => db_clean($_POST['name']),
		'code' => db_clean($_POST['code'])
	);
	$this->db->insert('codes', $data);	 
 }
  function addContent($page_id){
    if ($this->input->post('language')=="Greek"){
			$lang_id = 1;
			}
	elseif ($this->input->post('language')=="English"){
			$lang_id = 2;
			}

	$data = array( 
		'page_id' => $page_id,
		'lang_id' => $lang_id,
		'order' => db_clean($_POST['order']),
		'content' => $_POST['content']
	);

	$this->db->insert('pages_details', $data);	 
 }
  function addLeftcol($page_id){
    if ($this->input->post('language')=="Greek"){
			$lang_id = 1;
			}
	elseif ($this->input->post('language')=="English"){
			$lang_id = 2;
			}

	$data = array( 
		'page_id' => $page_id,
		'lang_id' => $lang_id,
		'title' => db_clean($_POST['title']),
		'text' => $_POST['text']
	);

	$this->db->insert('categories_title', $data);	 
 }

 function updatePage(){
	$data = array( 
		'name' => db_clean($_POST['name']),
		'keywords' => db_clean($_POST['keywords']),
		'description' => db_clean($_POST['description']),
		'status' => db_clean($_POST['status'],8),
		'path' => db_clean($_POST['path']),
		'content' => $_POST['content']

	);
 	$this->db->where('id', id_clean($_POST['id']));
	$this->db->update('pages', $data);	
 
 }
  function updateClient(){
	$data = array( 
		'cat_name' => db_clean($_POST['title'])
	);
 	$this->db->where('id', id_clean($_POST['id']));
	$this->db->update('client_category', $data);
	$data = array( 
		'name' => $_POST['clients']
	);
 	$this->db->where('client_category_id', id_clean($_POST['id']));
	$this->db->update('clients_details', $data);	
 
 }
  function updateCategories(){
	$data = array( 
		'title' => db_clean($_POST['title']),
		'text' => $_POST['text']
	);
 	$this->db->where('cat_id', id_clean($_POST['cat_id']));
	$this->db->update('categories_title', $data);
	
 }

  function updateTitle(){
	$data = array( 
		'title' => db_clean($_POST['title']),
	);
 	$this->db->where('title_id', id_clean($_POST['title_id']));
	$this->db->update('pages_title', $data);	
 
 }
  function updateSection(){
  if ($this->input->post('language')=="Greek"){
			$lang_id = 1;
			}
	elseif ($this->input->post('language')=="English"){
			$lang_id = 2;
			}
	$data = array( 
		'content' => $_POST['content'],
		'lang_id' => $lang_id,
		'order' => db_clean($_POST['order'])
	);
 	$this->db->where('section_id', id_clean($_POST['section_id']));
	$this->db->update('pages_details', $data);	
 
 }
 
 function deletePage($id){
 	//$data = array('status' => 'inactive');
 	$this->db->where('id', id_clean($id));
	//$this->db->update('pages', $data);
	$this->db->delete('pages');	
 }
  function deleteSection($section_id){
 	//$data = array('status' => 'inactive');
 	$this->db->where('section_id', id_clean($section_id));
	//$this->db->update('pages', $data);
	$this->db->delete('pages_details');	
 }
  function deleteCode($code_id){
 	//$data = array('status' => 'inactive');
 	$this->db->where('id', id_clean($code_id));
	//$this->db->update('pages', $data);
	$this->db->delete('codes');	
 }
  function deleteLeftCol($cat_id){
 	//$data = array('status' => 'inactive');
 	$this->db->where('cat_id', id_clean($cat_id));
	//$this->db->update('pages', $data);
	$this->db->delete('categories_title');	
 }

	
}

?>