<?php

class MPages extends Model{

	function Pages(){
	    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 getPage_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('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 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);
	$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 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 getAllClientsCategory($ld) {
 		$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) {
	  $ld=$this->session->userdata('lang_id');
 		$data = array();
		$this->db->select('*');
		$this->db->from('clients_details');
		//$this->db->join('clients_details','client_category.id=clients_details.client_category_id', 'left');
		$this->db->where('client_category_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 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 getPagePath($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 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 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 deletePage($id){
 	//$data = array('status' => 'inactive');
 	$this->db->where('id', id_clean($id));
	//$this->db->update('pages', $data);
	$this->db->delete('pages');	
 }
 
	
}

?>