<?php

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

class Crud_model extends CI_Model
{

   // protected $_table_name  = 'product_registration';
   // protected $_primary_key = 'id';
   // protected $_order_by    = "id desc";

    public function __construct()
    {
        parent::__construct();
    }
    function allcertifications_count()
    {
        
        $query = $this->db->get_where('certifications')->result();
        return count($query); 
    }
    function allcertifications($limit,$start)
    { 
        $query = $this->db->limit($limit,$start)->get_where('certifications');
        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function certification_search($limit,$start,$search)
    {
        $this->db->limit($limit,$start);
        //$this->db->order_by($col,$dir);
        $this->db->where("(id LIKE '%$search%' OR name LIKE '%$search%' OR photo LIKE '%$search%')");
        $query = $this->db->get('certifications');

        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function certification_search_count($search)
    {
        $this->db->where("(id LIKE '%$search%' OR name LIKE '%$search%' OR photo LIKE '%$search%')");
        $query = $this->db->get('certifications');

        return $query->num_rows();
    }
    function alloffers_count()
    {
        
        $query = $this->db->get_where('offers')->result();
        return count($query); 
    }
    function alloffers($limit,$start)
    { 
        $query = $this->db->limit($limit,$start)->get_where('offers');
        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function offer_search($limit,$start,$search)
    {
        $this->db->limit($limit,$start);
        //$this->db->order_by($col,$dir);
        $this->db->where("(id LIKE '%$search%' OR name LIKE '%$search%' OR photo LIKE '%$search%')");
        $query = $this->db->get('offers');

        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function offer_search_count($search)
    {
        $this->db->where("(id LIKE '%$search%' OR name LIKE '%$search%' OR photo LIKE '%$search%')");
        $query = $this->db->get('offers');

        return $query->num_rows();
    }
    function allclients_count()
    {
        
        $query = $this->db->get_where('clients')->result();
        return count($query); 
    }
    function allclients($limit,$start)
    { 
        $query = $this->db->limit($limit,$start)->get_where('clients');
        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function client_search($limit,$start,$search)
    {
        $this->db->limit($limit,$start);
        //$this->db->order_by($col,$dir);
        $this->db->where("(id LIKE '%$search%' OR name LIKE '%$search%' OR logo LIKE '%$search%' OR website LIKE '%$search%')");
        $query = $this->db->get('clients');

        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function client_search_count($search)
    {
        $this->db->where("(id LIKE '%$search%' OR name LIKE '%$search%' OR logo LIKE '%$search%' OR website LIKE '%$search%')");
        $query = $this->db->get('clients');

        return $query->num_rows();
    }
    function allblogs_count()
    {
        
        $query = $this->db->get_where('blogs')->result();
        return count($query); 
    }
    function allblogs($limit,$start)
    { 
        $query = $this->db->limit($limit,$start)->get_where('blogs');
        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function blog_search($limit,$start,$search)
    {
        $this->db->limit($limit,$start);
        //$this->db->order_by($col,$dir);
        $this->db->where("(id LIKE '%$search%' OR title LIKE '%$search%' OR posted_by LIKE '%$search%' OR posted_date LIKE '%$search%' OR content LIKE '%$search%')");
        $query = $this->db->get('blogs');

        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function blog_search_count($search)
    {
        $this->db->where("(id LIKE '%$search%' OR title LIKE '%$search%' OR posted_by LIKE '%$search%' OR posted_date LIKE '%$search%' OR content LIKE '%$search%')");
        $query = $this->db->get('blogs');

        return $query->num_rows();
    }
    public function blog_record_count() {
 
       //return $this->db->get_where('blogs', array('status' => '1'))->count_all_results();
       return $this->db->where('status',1)->from("blogs")->count_all_results();
     }
    public function fetch_blogs($limit, $start) {
 
       $this->db->limit($limit, $start);
 
      // $query = $this->db->get("blogs");
       $query = $this->db->order_by('posted_date desc')->get_where('blogs', array('status' => '1'));
 
 
       if ($query->num_rows() > 0) {
 
           foreach ($query->result() as $row) {
 
               $data[] = $row;
 
           }
 
           return $data;
 
       }
 
       return false;
 
   }
    function allcalls_count()
    {
        
        $query = $this->db->get_where('call_back')->result();
        return count($query); 
    }
    function allcalls($limit,$start)
    { 
        $query = $this->db->limit($limit,$start)->get_where('call_back');
        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function call_search($limit,$start,$search)
    {
        $this->db->limit($limit,$start);
        //$this->db->order_by($col,$dir);
        $this->db->where("(id LIKE '%$search%' OR phone LIKE '%$search%')");
        $query = $this->db->get('call_back');

        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function call_search_count($search)
    {
        $this->db->where("(id LIKE '%$search%' OR phone LIKE '%$search%')");
        $query = $this->db->get('call_back');

        return $query->num_rows();
    }
    function allapplicants_count()
    {
        
        $query = $this->db->get_where('applications')->result();
        return count($query); 
    }
    function allapplicants($limit,$start)
    { 
        $query = $this->db->limit($limit,$start)->get_where('applications');
        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function applicant_search($limit,$start,$search)
    {
        $this->db->limit($limit,$start);
        //$this->db->order_by($col,$dir);
        $this->db->where("(id LIKE '%$search%' OR name LIKE '%$search%' OR email LIKE '%$search%' OR phone LIKE '%$search%' OR course LIKE '%$search%' OR message LIKE '%$search%')");
        $query = $this->db->get('applications');

        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function applicant_search_count($search)
    {
        $this->db->where("(id LIKE '%$search%' OR name LIKE '%$search%' OR email LIKE '%$search%' OR phone LIKE '%$search%' OR course LIKE '%$search%' OR message LIKE '%$search%')");
        $query = $this->db->get('applications');

        return $query->num_rows();
    }
    function alldownloads_count()
    {
        
        $query = $this->db->get_where('download_brochure')->result();
        return count($query); 
    }
    function alldownloads($limit,$start)
    { 
        $query = $this->db->limit($limit,$start)->get_where('download_brochure');
        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function download_search($limit,$start,$search)
    {
        $this->db->limit($limit,$start);
        //$this->db->order_by($col,$dir);
        $this->db->where("(id LIKE '%$search%' OR first_name LIKE '%$search%' OR email LIKE '%$search%' OR phone LIKE '%$search%' OR last_name LIKE '%$search%')");
        $query = $this->db->get('download_brochure');

        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function download_search_count($search)
    {
        $this->db->where("(id LIKE '%$search%' OR first_name LIKE '%$search%' OR email LIKE '%$search%' OR phone LIKE '%$search%' OR last_name LIKE '%$search%')");
        $query = $this->db->get('download_brochure');

        return $query->num_rows();
    }
    function allcontacts_count()
    {
        
        $query = $this->db->get_where('contact_us')->result();
        return count($query); 
    }
    function allcontacts($limit,$start)
    { 
        $query = $this->db->limit($limit,$start)->get_where('contact_us');
        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function contacts_search($limit,$start,$search)
    {
        $this->db->limit($limit,$start);
        //$this->db->order_by($col,$dir);
        $this->db->where("(id LIKE '%$search%' OR name LIKE '%$search%' OR email LIKE '%$search%' OR phone LIKE '%$search%' OR message LIKE '%$search%')");
        $query = $this->db->get('contact_us');

        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function contacts_search_count($search)
    {
        $this->db->where("(id LIKE '%$search%' OR name LIKE '%$search%' OR email LIKE '%$search%' OR phone LIKE '%$search%' OR message LIKE '%$search%')");
        $query = $this->db->get('contact_us');

        return $query->num_rows();
    }
    /////////////////////////////////////////////////////////////////////////////
    function allbanners_count()
    {
        
        $query = $this->db->get_where('banner')->result();
        return count($query); 
    }
    function allbanners($limit,$start)
    { 
        $query = $this->db->limit($limit,$start)->get_where('banner');
        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function banner_search($limit,$start,$search)
    {
        $this->db->limit($limit,$start);
        //$this->db->order_by($col,$dir);
        $this->db->where("(id LIKE '%$search%' OR title LIKE '%$search%' OR content LIKE '%$search%')");
        $query = $this->db->get('banner');

        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function banner_search_count($search)
    {
        $this->db->where("(id LIKE '%$search%' OR title LIKE '%$search%' OR content LIKE '%$search%')");
        $query = $this->db->get('banner');

        return $query->num_rows();
    }
     function allcourses_count()
    {
        
        $query = $this->db->get_where('courses')->result();
        return count($query); 
    }
    function allcourses($limit,$start)
    { 
        $query = $this->db->limit($limit,$start)->get_where('courses');
        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function course_search($limit,$start,$search)
    {
        $this->db->limit($limit,$start);
        //$this->db->order_by($col,$dir);
        $this->db->where("(id LIKE '%$search%' OR title LIKE '%$search%' OR content LIKE '%$search%')");
        $query = $this->db->get('courses');

        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function course_search_count($search)
    {
        $this->db->where("(id LIKE '%$search%' OR title LIKE '%$search%' OR content LIKE '%$search%')");
        $query = $this->db->get('courses');

        return $query->num_rows();
    }
     function alltestimonials_count()
    {
        
        $query = $this->db->get_where('testimonials')->result();
        return count($query); 
    }
    function alltestimonials($limit,$start)
    { 
        $query = $this->db->limit($limit,$start)->get_where('testimonials');
        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function testimonial_search($limit,$start,$search)
    {
        $this->db->limit($limit,$start);
        //$this->db->order_by($col,$dir);
        $this->db->where("(id LIKE '%$search%' OR name LIKE '%$search%' OR note LIKE '%$search%')");
        $query = $this->db->get('testimonials');

        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function testimonial_search_count($search)
    {
        $this->db->where("(id LIKE '%$search%' OR name LIKE '%$search%' OR note LIKE '%$search%')");
        $query = $this->db->get('testimonials');

        return $query->num_rows();
    }
    function acca_allapplicants_count()
    {
        
        $query = $this->db->get_where('acca_enquiry')->result();
        return count($query); 
    }
    function acca_allapplicants($limit,$start)
    { 
        $query = $this->db->limit($limit,$start)->get_where('acca_enquiry');
        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function acca_applicant_search($limit,$start,$search)
    {
        $this->db->limit($limit,$start);
        //$this->db->order_by($col,$dir);
        $this->db->where("(id LIKE '%$search%' OR name LIKE '%$search%' OR email LIKE '%$search%' OR phone LIKE '%$search%' OR course LIKE '%$search%' OR message LIKE '%$search%')");
        $query = $this->db->get('acca_enquiry');

        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function acca_applicant_search_count($search)
    {
        $this->db->where("(id LIKE '%$search%' OR name LIKE '%$search%' OR email LIKE '%$search%' OR phone LIKE '%$search%' OR course LIKE '%$search%' OR message LIKE '%$search%')");
        $query = $this->db->get('acca_enquiry');

        return $query->num_rows();
    }
    function allcourse_details_count()
    {
        
        $query = $this->db->get_where('course_page')->result();
        return count($query); 
    }
    function allcourse_details($limit,$start)
    { 
        $query = $this->db->limit($limit,$start)->get_where('course_page');
        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function course_details_search($limit,$start,$search)
    {
        $this->db->limit($limit,$start);
        //$this->db->order_by($col,$dir);
        $this->db->where("(id LIKE '%$search%' OR description LIKE '%$search%' OR features LIKE '%$search%')");
        $query = $this->db->get('course_page');

        if($query->num_rows()>0)
        {
            return $query->result();
        }
        else
        {
            return null;
        }
    }
    function course_details_search_count($search)
    {
        $this->db->where("(id LIKE '%$search%' OR description LIKE '%$search%' OR features LIKE '%$search%')");
        $query = $this->db->get('course_page');

        return $query->num_rows();
    }
}
