<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class RT_Exceptions extends CI_Exceptions {

    public function show_404($page = '', $log_error = TRUE) {
        $CI = & get_instance();
        $CI->lang->load('ciext/core');

        $heading = $CI->lang->line('404_head');
        $message = $CI->lang->line('404_body');

        // By default we log this, but allow a dev to skip it
        if ($log_error) {
            $page = (!empty($page)) ? $page : $CI->uri->uri_string();
            log_message('error', '404 Page Not Found --> ' . $page);
        }
        
        // try load 404 from DB
        if ($CI->load->is_loaded('session')) {
            $CI->load->model('ciext/core_model');
            $page_404 = $CI->core_model->get_page('404');
            if (!empty($page_404)) {

                echo $page_404;
                exit;
            }
        }

        echo $this->show_error($heading, $message, 'error_404', 404);
        exit;
    }

}
