<?php
class CMS_Model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    public function fetchPage($pageName)
    {
        /*$query="SELECT content_manager.* from content_manager
 LEFT JOIN content_manager c ON (c.province_id=content_manager.province_id AND c.province_id='".$this->session->province."') 
 WHERE content_manager.url LIKE '%".$pageName."%' ORDER BY content_manager.id ASC";*/


        $query = "SELECT content_manager.* from content_manager
        where content_manager.province_id='" . $this->session->province . "' 
        and content_manager.url LIKE '%" . $pageName . "%' ORDER BY content_manager.id DESC";

        $result = $this->db->query($query);

        //return $this->db->last_query();

        if ($result->num_rows() == 0) {
            return false;
        } else {
            return $result->row(1);
        }
    }

    public function fetchMessage($pageName, $locationId)
    {
        $query = "SELECT * from content_manager
        WHERE url LIKE '%" . $pageName . "%' AND province_id='$locationId'";
        $result = $this->db->query($query);
        if ($result->num_rows() == 0) {
            return false;
        } else {
            return $result->row(1);
        }
    }

    public function pageContent($pageName)
    {
        $query = "SELECT page_title, meta_description, extra_tags, page_description, headerImage, province_id from content_manager
        where province_id='" . $this->session->province . "' 
        and url = '" . $pageName . "'";

        $result = $this->db->query($query);

        if ($result->num_rows() == 0) {
            return false;
        } else {
            return $result->row(1);
        }
    }
}
