<?php

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

class Admin extends MY_Controller
{
     public function __construct()
    {

        parent::__construct();
       
    }

    public function index()
    {
        /*$data['title']    = "Dashboard";
        $data['page_name']    = "dashboard";
        //$data['count_rooms'] = $this->db->get_where('ht_room')->num_rows();
        
        //$data['count_reserv'] = $this->db->get_where('ht_reservation')->num_rows();
        
        $this->load->view('back/dashboard.php' , $data);*/
        redirect('admin/applications');
    }
    
    public function certifications()
    {
      $data['title']    = "Affliations";
      $data['page_name']    = "affliations";
      $this->load->view('back/certifications.php' , $data);
    }
    public function list_certifications()
    {
     
      $limit = $this->input->post('length');
	  $start = $this->input->post('start');  
	  
      $totalData = $this->crud_model->allcertifications_count();

		        $totalFiltered = $totalData;

		        if(empty($this->input->post('search')['value']))
		        {
                   
                      $certifications = $this->crud_model->allcertifications($limit,$start); 
		        	
		        }
		        else {
		            $search = $this->input->post('search')['value'];

		            $certifications =  $this->crud_model->certification_search($limit,$start,$search);

		            $totalFiltered = $this->crud_model->certification_search_count($search);
		        }

		        $data = array();
                $no = $this->input->post('start');
		        if(!empty($certifications))
		        {
		        	
		            foreach ($certifications as $certification)
		            {   
                        $no++;
                        $date = $certification->date_created;
                        $date_created = date("d-m-Y", $date);
                        $nestedData['#'] = $no ;
                        $nestedData['name'] = $certification->name ;
                        $nestedData['photo'] = "<a target='_blank' href='".base_url()."uploads/front/certifications/".$certification->photo."'><img alt='image' src='".base_url()."uploads/front/certifications/".$certification->photo."' class='' width='45'></a>";
                        $nestedData['options'] = "<a class='add-tooltip' data-toggle='tooltip' data-placement='top' title='Delete' ><i data-target='#delete_modal".$certification->id."' data-toggle='modal' class='fas fa-trash-alt' style='font-size: 1.5em'></i></a>";
                        
		                $data[] = $nestedData;
		            }
		        }

		        $json_data = array(
		                    "draw"            => intval($this->input->post('draw')),
		                    "recordsTotal"    => intval($totalData),
		                    "recordsFiltered" => intval($totalFiltered),
		                    "data"            => $data
		                    );
		        echo json_encode($json_data);
    }
    public function delete_certification($id)
    {
         
    $this->db->where('id', $id);
    $result = $this->db->delete('certifications');
    if ($result) {
     $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Deleted Successfully</small></div>');
     redirect('admin/certifications');    
    } else {
    $this->session->set_flashdata('msg', '<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Error ! Cannot delete the record</small></div>');
     redirect('admin/certifications');    
    }
    }
      public function add_certification()
    {
      
      if($_POST){
        $name = $this->input->post('name');
        $cer_data = array(
            'name'     => $this->input->post('name'),
            'date_created'       => time(),
           ); 
          
          //pic upload   
           
         $config['upload_path'] = './uploads/front/certifications/';
        // $config['allowed_types'] = 'docx|docs|txt|pdf|xls|JPG|jpg|png|jpeg';
         $config['allowed_types'] = '*';
         $config['encrypt_name']=true;
         $this->load->library('upload', $config);
         $this->upload->initialize($config);  
           
         $img = "certificate";
         
         if (! empty($_FILES['certificate']['name']) && ! $this->upload->do_upload($img))
          {
          $this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Please Upload a Valid Photo</div>');
            redirect('admin/cerfitications');
          } else {
           
          $data = array('upload_data' => $this->upload->data());

          $field_data = $this->upload->data();
          $image = $field_data['file_name']; 
          $cer_data['photo'] = $image;
          }
          
         $this->db->insert('certifications', $cer_data);
         $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Added Successfully</small></div>');
         redirect('admin/certifications');
      }  
    }
    public function clients()
    {
      $data['title']    = "Clients";
      $data['page_name']    = "clients";
      $this->load->view('back/clients.php' , $data);
    }
    public function list_clients()
    {
     
      $limit = $this->input->post('length');
	  $start = $this->input->post('start');  
	  
      $totalData = $this->crud_model->allclients_count();

		        $totalFiltered = $totalData;

		        if(empty($this->input->post('search')['value']))
		        {
                   
                      $clients = $this->crud_model->allclients($limit,$start); 
		        	
		        }
		        else {
		            $search = $this->input->post('search')['value'];

		            $clients =  $this->crud_model->client_search($limit,$start,$search);

		            $totalFiltered = $this->crud_model->client_search_count($search);
		        }

		        $data = array();
                $no = $this->input->post('start');
		        if(!empty($clients))
		        {
		        	
		            foreach ($clients as $client)
		            {   
                        $no++;
                        $date = $client->date_created;
                        $date_created = date("d-m-Y", $date);
                        $nestedData['#'] = $no ;
                        $nestedData['name'] = $client->name ;
                        $nestedData['website'] = $client->website ;
                        $nestedData['logo'] = "<a target='_blank' href='".base_url()."uploads/front/clients/".$client->logo."'><img alt='image' src='".base_url()."uploads/front/clients/".$client->logo."' class='' width='45'></a>";
                        $nestedData['options'] = "<a class='add-tooltip' data-toggle='tooltip' data-placement='top' title='Delete' ><i data-target='#delete_modal".$client->id."' data-toggle='modal' class='fas fa-trash-alt' style='font-size: 1.5em'></i></a>";
                        
		                $data[] = $nestedData;
		            }
		        }

		        $json_data = array(
		                    "draw"            => intval($this->input->post('draw')),
		                    "recordsTotal"    => intval($totalData),
		                    "recordsFiltered" => intval($totalFiltered),
		                    "data"            => $data
		                    );
		        echo json_encode($json_data);
    }
    public function delete_client($id)
    {
         
    $this->db->where('id', $id);
    $result = $this->db->delete('clients');
    if ($result) {
     $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Deleted Successfully</small></div>');
     redirect('admin/clients');    
    } else {
    $this->session->set_flashdata('msg', '<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Error ! Cannot delete the record</small></div>');
     redirect('admin/clients');    
    }
    }
      public function add_client()
    {
      
      if($_POST){
        $name = $this->input->post('name');
        $website = $this->input->post('website');
        $client_data = array(
            'name'     => $this->input->post('name'),
            'website'     => $this->input->post('website'),
            'date_created'       => time(),
           ); 
          
          //pic upload   
           
         $config['upload_path'] = './uploads/front/clients/';
        // $config['allowed_types'] = 'docx|docs|txt|pdf|xls|JPG|jpg|png|jpeg';
         $config['allowed_types'] = '*';
         $config['encrypt_name']=true;
         $this->load->library('upload', $config);
         $this->upload->initialize($config);  
           
         $img = "logo";
         
         if (! empty($_FILES['logo']['name']) && ! $this->upload->do_upload($img))
          {
          $this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Please Upload a Valid Photo</div>');
            redirect('admin/clients');
          } else {
           
          $data = array('upload_data' => $this->upload->data());

          $field_data = $this->upload->data();
          $image = $field_data['file_name']; 
          $client_data['logo'] = $image;
          }
          
         $this->db->insert('clients', $client_data);
         $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Added Successfully</small></div>');
         redirect('admin/clients');
      }  
    }
    public function gallery()
    {
      $data['title']    = "Gallery";
      $data['page_name']    = "gallery";
      $this->load->view('back/gallery.php' , $data);
    }
    public function delete_gallery_photo($id)
    {
         
    $this->db->where('id', $id);
    $result = $this->db->delete('gallery');
    if ($result) {
     $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Deleted Successfully</small></div>');
     redirect('admin/gallery');    
    } else {
    $this->session->set_flashdata('msg', '<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Error ! Cannot delete the record</small></div>');
     redirect('admin/gallery');    
    }
    }
      public function add_gallery_photo()
    {
      
      if($_POST){
        $name = $this->input->post('name');
        $type =  $this->input->post('type');
        $gallery = array(
            'name'     => $this->input->post('name'),
            'type'     => $type,
            'date_created'       => time(),
           ); 
          
          //pic upload   
           
         $config['upload_path'] = './uploads/front/gallery/';
        // $config['allowed_types'] = 'docx|docs|txt|pdf|xls|JPG|jpg|png|jpeg';
         $config['allowed_types'] = '*';
         $config['encrypt_name']=true;
         $this->load->library('upload', $config);
         $this->upload->initialize($config);  
           
         $img = "photo";
         
         if (! empty($_FILES['photo']['name']) && ! $this->upload->do_upload($img))
          {
          $this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Please Upload a Valid Photo</div>');
            redirect('admin/gallery');
          } else {
           
          $data = array('upload_data' => $this->upload->data());

          $field_data = $this->upload->data();
          $image = $field_data['file_name']; 
          $gallery['photo'] = $image;
          }
         if($type=='1'){
             //update banner
             $this->db->where('type', 1)->update('gallery', $gallery);
         }else{
             //add media gallery
             $this->db->insert('gallery', $gallery);  
         } 
         
         $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Added Successfully</small></div>');
         redirect('admin/gallery');
      }  
    }
    public function testimonials()
    {
      $data['title']    = "Testimonials";
      $data['page_name']    = "testimonials";
      $this->load->view('back/testimonials.php' , $data);
    }
     public function add_testimonial($id='')
    {
      if(empty($id)) {
      $data['title']    = "Add Testimonial";
      $data['page_name']    = "add_testimonial"; 
      } else {
      $data['title']     = "Edit Testimonial";
      $data['page_name'] = "edit_testimonial";
      $data['testimonial_data']   = $this->db->get_where('testimonials', array('id'=>$id))->row();    
      } 
      $this->load->view('back/add_testimonial.php' , $data); 
    }
    public function do_add_testimonial($id ='')
    {
      $data['title']    = "Add Testimonial";
      $data['page_name']    = "do_add_testimonial"; 
      if($_POST){
      $status = '0';  
      if($this->input->post('status')) $status = '1';    
        $test = array(
            'name'     => $this->input->post('name'),
            'note'    => $this->input->post('textarea1'),
            'designation'    => $this->input->post('designation'),
           ); 
          //main pic upload   
           
         $config['upload_path'] = './uploads/front/testimonial/';
        // $config['allowed_types'] = 'docx|docs|txt|pdf|xls|JPG|jpg|png|jpeg';
         $config['allowed_types'] = '*';
         $config['encrypt_name']=true;
         $this->load->library('upload', $config);
         $this->upload->initialize($config);  
           
         $img = "main_image";
         
         if (! empty($_FILES['main_image']['name']) && ! $this->upload->do_upload($img))
          {
          $this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Please Upload a Valid Photo</div>');
            redirect('admin/add_testimonial');
          } else {
           
          $data = array('upload_data' => $this->upload->data());

          $field_data = $this->upload->data();
          $image = $field_data['file_name']; 
          $test['photo'] = $image;  
          }
         if(empty($id)) { 
         $blog['date_created'] = time(); 
         $this->db->insert('testimonials', $test);
         $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Added Successfully</small></div>');
         } else {
         if(empty($_FILES['main_image']['name'])) {
         $test['photo'] = $this->input->post('ext_photo');     
         }     
         $this->db->where('id', $id)->update('testimonials', $test);
         $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Updated Successfully</small></div>');    
         }    
         redirect('admin/testimonials');     
      }  
    }
     public function list_testimonials()
    {
     
      $limit = $this->input->post('length');
	  $start = $this->input->post('start');  
	  
      $totalData = $this->crud_model->alltestimonials_count();

		        $totalFiltered = $totalData;

		        if(empty($this->input->post('search')['value']))
		        {
                   
                      $tests = $this->crud_model->alltestimonials($limit,$start); 
		        	
		        }
		        else {
		            $search = $this->input->post('search')['value'];

		            $tests =  $this->crud_model->testimonial_search($limit,$start,$search);

		            $totalFiltered = $this->crud_model->testimonial_search_count($search);
		        }

		        $data = array();
                $no = $this->input->post('start');
		        if(!empty($tests))
		        {
		        	
		            foreach ($tests as $test)
		            {   
                        $no++;
                        $content = strip_tags($test->note);
                        $nestedData['#'] = $no ;
                        $nestedData['note'] = $content ;
                        $nestedData['designation'] = $test->designation ;
                        $nestedData['person'] = "<a target='_blank' href='".base_url()."uploads/front/testimonial/".$test->photo."'><img alt='image' src='".base_url()."uploads/front/testimonial/".$test->photo."' class='' width='45'></a><br/>".$test->name."";
                        $nestedData['options'] = "<a href='".base_url()."admin/add_testimonial/".$test->id."' class='add-tooltip' data-toggle='tooltip' data-placement='top' title='Edit' ><i class='far fa-edit' style='font-size: 1.5em'></i></a><a class='add-tooltip' data-toggle='tooltip' data-placement='top' title='Delete' ><i data-target='#delete_modal".$test->id."' data-toggle='modal' class='fas fa-trash-alt' style='font-size: 1.5em'></i></a>";
                        
		                $data[] = $nestedData;
		            }
		        }

		        $json_data = array(
		                    "draw"            => intval($this->input->post('draw')),
		                    "recordsTotal"    => intval($totalData),
		                    "recordsFiltered" => intval($totalFiltered),
		                    "data"            => $data
		                    );
		        echo json_encode($json_data);
    }
    public function delete_testimonial($id)
    {
         
    $this->db->where('id', $id);
    $result = $this->db->delete('testimonials');
    if ($result) {
     $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Deleted Successfully</small></div>');
     redirect('admin/testimonials');    
    } else {
    $this->session->set_flashdata('msg', '<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Error ! Cannot delete the record</small></div>');
     redirect('admin/testimonials');    
    }
    }
    public function manage_category_pages()
    {
      $data['title']    = "Manage Course Pages";
      $data['page_name']    = "manage_course_pages";
      $this->load->view('back/course_pages.php' , $data);
    }
    public function add_course_pages($id='')
    {
      if(empty($id)) {
      $data['title']    = "Add Course Details";
      $data['page_name']    = "add_course_details"; 
      $data['category_data']   = $this->db->get_where('prepare_category', array('parent_id'=>'0'))->result();
      } else {
      $data['title']     = "Edit Course Details";
      $data['page_name'] = "edit_course_details";
      $data['category_data']   = $this->db->get_where('prepare_category', array('parent_id'=>'0'))->result();
      $data['course_data']   = $this->db->get_where('course_page', array('id'=>$id))->row();    
      } 
      $this->load->view('back/add_course_page' , $data); 
    }
    public function do_add_course_details($id ='')
    {
      $data['title']    = "Add Course Details";
      $data['page_name']    = "do_add_course_details"; 
      if($_POST){   
        $det = array(
            'category'     => $this->input->post('category'),
            'description'    => $this->input->post('textarea1'),
            'features'    => $this->input->post('textarea2'),
            'title'    => $this->input->post('banner_title'),
           ); 
          //main pic upload   
           
         $config['upload_path'] = './uploads/front/banner_image/';
        // $config['allowed_types'] = 'docx|docs|txt|pdf|xls|JPG|jpg|png|jpeg';
         $config['allowed_types'] = '*';
         $config['encrypt_name']=true;
         $this->load->library('upload', $config);
         $this->upload->initialize($config);  
           
         $img = "main_image";
         
         if (! empty($_FILES['main_image']['name']) && ! $this->upload->do_upload($img))
          {
          $this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Please Upload a Valid Banner image</div>');
            redirect('admin/add_course_pages');
          } else {
           
          $data = array('upload_data' => $this->upload->data());

          $field_data = $this->upload->data();
          $image = $field_data['file_name']; 
          $det['banner'] = $image;  
          }
          
          //pic 2 upload
           $config['upload_path'] = './uploads/front/courses/';
        // $config['allowed_types'] = 'docx|docs|txt|pdf|xls|JPG|jpg|png|jpeg';
         $config['allowed_types'] = '*';
         $config['encrypt_name']=true;
         $this->load->library('upload', $config);
         $this->upload->initialize($config);
          
          $img = "main_image1";
          
         if (! empty($_FILES['main_image1']['name']) && ! $this->upload->do_upload($img))
          {
          $this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Please Upload a Valid description image</div>');
            redirect('admin/add_course_pages');
          } else {
           
          $data = array('upload_data' => $this->upload->data());

          $field_data = $this->upload->data();
          $image = $field_data['file_name']; 
          $det['sec_image'] = $image;  
          }
          
         if(empty($id)) { 
         $this->db->insert('course_page', $det);
         $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Added Successfully</small></div>');
         } else {
         if(empty($_FILES['main_image']['name'])) {
         $det['banner'] = $this->input->post('ext_photo');     
         } 
        if(empty($_FILES['main_image1']['name'])) {
         $det['sec_image'] = $this->input->post('ext_photo1');     
         }     
         $this->db->where('id', $id)->update('course_page', $det);
         $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Updated Successfully</small></div>');    
         }    
         redirect('admin/manage_category_pages');     
      }  
    }
    public function blog()
    {
      $data['title']    = "Blogs";
      $data['page_name']    = "blogs";
      $this->load->view('back/blogs.php' , $data);
    }
     public function add_blog($id='')
    {
      if(empty($id)) {
      $data['title']    = "Add Blog";
      $data['page_name']    = "add_blog"; 
      } else {
      $data['title']     = "Edit Blog";
      $data['page_name'] = "edit_blog";
      $data['blog_data']   = $this->db->get_where('blogs', array('id'=>$id))->row();    
      } 
      $this->load->view('back/add_blog.php' , $data); 
    }
    public function do_add_blog($id ='')
    {
      $data['title']    = "Add Blog";
      $data['page_name']    = "do_add_blog"; 
      if($_POST){
      $status = '0';  
      if($this->input->post('status')) $status = '1';    
        $blog = array(
            'title'     => $this->input->post('title'),
            'content'    => $this->input->post('textarea1'),
            'posted_by'    => 'Admin',
            'posted_date'    => $this->input->post('date_posted'),
            'status'    => $status,
           ); 
          //main pic upload   
           
         $config['upload_path'] = './uploads/front/blog_image/';
        // $config['allowed_types'] = 'docx|docs|txt|pdf|xls|JPG|jpg|png|jpeg';
         $config['allowed_types'] = '*';
         $config['encrypt_name']=true;
         $this->load->library('upload', $config);
         $this->upload->initialize($config);  
           
         $img = "main_image";
         
         if (! empty($_FILES['main_image']['name']) && ! $this->upload->do_upload($img))
          {
          $this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Please Upload a Valid Photo</div>');
            redirect('admin/add_blog');
          } else {
           
          $data = array('upload_data' => $this->upload->data());

          $field_data = $this->upload->data();
          $image = $field_data['file_name']; 
          $blog['photo'] = $image;  
          }
         if(empty($id)) { 
         $blog['date_created'] = time(); 
         $this->db->insert('blogs', $blog);
         $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Added Successfully</small></div>');
         } else {
         if(empty($_FILES['main_image']['name'])) {
         $blog['photo'] = $this->input->post('ext_photo');     
         }     
         $this->db->where('id', $id)->update('blogs', $blog);
         $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Updated Successfully</small></div>');    
         }    
         redirect('admin/blog');     
      }  
    }
    public function list_blogs()
    {
     
      $limit = $this->input->post('length');
	  $start = $this->input->post('start');  
	  
      $totalData = $this->crud_model->allblogs_count();

		        $totalFiltered = $totalData;

		        if(empty($this->input->post('search')['value']))
		        {
                   
                      $blogs = $this->crud_model->allblogs($limit,$start); 
		        	
		        }
		        else {
		            $search = $this->input->post('search')['value'];

		            $blogs =  $this->crud_model->blog_search($limit,$start,$search);

		            $totalFiltered = $this->crud_model->blog_search_count($search);
		        }

		        $data = array();
                $no = $this->input->post('start');
		        if(!empty($blogs))
		        {
		        	
		            foreach ($blogs as $blog)
		            {   
                        $no++;
                        $date = $blog->date_created;
                        $date_created = date("d-m-Y", $date);
                        $posted_date = $blog->posted_date;
                        $posted_date = date("d-m-Y", strtotime($posted_date));
                        $blog_status = $blog->status;
                        $content = strip_tags($blog->content);
                        
                        if($blog_status == '1') {
                        $status      = "<i class='fas fa-check-circle' style='font-size: 1.3em;color:green;'></i>"; } else {
                        $status      = "<i class='fas fa-times-circle' style='font-size: 1.3em;color:red;'></i>"; }
                        $nestedData['#'] = $no ;
                        $nestedData['title'] = $blog->title ;
                        $nestedData['content'] = $content ;
                        $nestedData['posted_by'] = $blog->posted_by ;
                        $nestedData['date'] = $posted_date ;
                        $nestedData['status'] = $status ;
                        $nestedData['photo'] = "<a target='_blank' href='".base_url()."uploads/front/blog_image/".$blog->photo."'><img alt='image' src='".base_url()."uploads/front/blog_image/".$blog->photo."' class='' width='45'></a>";
                        $nestedData['options'] = "<a href='".base_url()."admin/add_blog/".$blog->id."' class='add-tooltip' data-toggle='tooltip' data-placement='top' title='Edit' ><i class='far fa-edit' style='font-size: 1.5em'></i></a><a class='add-tooltip' data-toggle='tooltip' data-placement='top' title='Delete' ><i data-target='#delete_modal".$blog->id."' data-toggle='modal' class='fas fa-trash-alt' style='font-size: 1.5em'></i></a>";
                        
		                $data[] = $nestedData;
		            }
		        }

		        $json_data = array(
		                    "draw"            => intval($this->input->post('draw')),
		                    "recordsTotal"    => intval($totalData),
		                    "recordsFiltered" => intval($totalFiltered),
		                    "data"            => $data
		                    );
		        echo json_encode($json_data);
    }
    public function delete_blog($id)
    {
         
    $this->db->where('id', $id);
    $result = $this->db->delete('blogs');
    if ($result) {
     $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Deleted Successfully</small></div>');
     redirect('admin/blog');    
    } else {
    $this->session->set_flashdata('msg', '<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Error ! Cannot delete the record</small></div>');
     redirect('admin/blog');    
    }
    }
     public function prepare_categories()
    {
      $data['title']    = "Categories & Subcategories";
      $data['page_name']    = "prepare_categories";
      $data['prepare']   = $this->db->get('prepare_category')->result();
      $this->load->view('back/prepare_category.php' , $data);
    }
     public function add_prep_category()
    {
      
      if($_POST){
        $name = $this->input->post('name');
        $parent_id = $this->input->post('parent_id');
        $slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $name)));
        $c_data = array(
            'name'     => $name,
            'parent_id'     => $parent_id,
            'slug' => $slug
           ); 
          
          
         $this->db->insert('PREPARE_CATEGORY', $c_data);
         $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Added Successfully</small></div>');
         redirect('admin/prepare_categories');
      }  
    }
     public function slug()
    {
       $cs=  $this->db->get('prepare_category')->result();
         foreach($cs as $c){
             $slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $c->name)));
           $det = array(
            'slug'     => $slug
                 );
             $this->db->where('id', $c->id)->update('prepare_category', $det);
         }
         
     }
    public function delete_prepare_category($id ='')
    {    
     //delete category   
    $this->db->where('id', $id);
    $result = $this->db->delete('prepare_category');
     //delete subcategories   
    $this->db->where('parent_id', $id);
    $result2 = $this->db->delete('prepare_category');   
    if ($result) {
     $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Deleted Successfully</small></div>');
     redirect('admin/prepare_categories');    
    } else {
    $this->session->set_flashdata('msg', '<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Error ! Cannot delete the record</small></div>');
     redirect('admin/prepare_categories');    
    }
    }
    public function why_choose_us()
    {
      $data['title']    = "Why Choose Us";
      $data['page_name']    = "why_choose_us";
      $data['why']   = $this->db->get('why_choose_us')->result();
      $this->load->view('back/why_choose_us.php' , $data);
    }
    public function add_why_choose_us($id='')
    {
      if(empty($id)) {
      $data['title']    = "Add Why Choose Us";
      $data['page_name']    = "add_why_choose_us"; 
      } else {
      $data['title']     = "Edit Why Choose Us";
      $data['page_name'] = "edit_why_choose_us";
      $data['why']   = $this->db->get_where('why_choose_us', array('id'=>$id))->row();    
      } 
      $this->load->view('back/add_why_choose_us.php' , $data); 
    }
    public function delete_why($id ='')
    {    
    $this->db->where('id', $id);
    $result = $this->db->delete('why_choose_us');
    if ($result) {
     $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Deleted Successfully</small></div>');
     redirect('admin/why_choose_us');    
    } else {
    $this->session->set_flashdata('msg', '<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Error ! Cannot delete the record</small></div>');
     redirect('admin/why_choose_us');    
    }
    }
     public function do_add_why($id ='')
    {
      $data['title']    = "Add Why Choose Us";
      $data['page_name']    = "do_add_why"; 
      if($_POST){    
        $det = array(
            'title'     => $this->input->post('title'),
            'content'    => $this->input->post('textarea1'),
            'icon'    => $this->input->post('icon'),
           ); 
         
         if(empty($id)) { 
         $this->db->insert('why_choose_us', $det);
         $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Added Successfully</small></div>');
         } else {    
         $this->db->where('id', $id)->update('why_choose_us', $det);
         $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Updated Successfully</small></div>');    
         }    
         redirect('admin/why_choose_us');     
      }  
    }
    public function courses()
    {
      $data['title']    = "Courses";
      $data['page_name']    = "courses";
      $this->load->view('back/courses.php' , $data);
    }
    public function add_courses($id='')
    {
      if(empty($id)) {
      $data['title']    = "Add Course";
      $data['page_name']    = "add_courses"; 
      } else {
      $data['title']     = "Edit Courses";
      $data['page_name'] = "edit_courses";
      $data['course_data']   = $this->db->get_where('courses', array('id'=>$id))->row();    
      } 
      $this->load->view('back/add_course.php' , $data); 
    }
    public function do_add_course($id ='')
    {
      $data['title']    = "Add Course";
      $data['page_name']    = "do_add_course"; 
      if($_POST){    
        $course = array(
            'title'     => $this->input->post('title'),
            'content'    => $this->input->post('textarea1'),
           ); 
          //main pic upload   
           
         $config['upload_path'] = './uploads/front/courses/';
        // $config['allowed_types'] = 'docx|docs|txt|pdf|xls|JPG|jpg|png|jpeg';
         $config['allowed_types'] = '*';
         $config['encrypt_name']=true;
         $this->load->library('upload', $config);
         $this->upload->initialize($config);  
           
         $img = "main_image";
         
         if (! empty($_FILES['main_image']['name']) && ! $this->upload->do_upload($img))
          {
          $this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Please Upload a Valid Photo</div>');
            redirect('admin/add_courses');
          } else {
           
          $data = array('upload_data' => $this->upload->data());

          $field_data = $this->upload->data();
          $image = $field_data['file_name']; 
          $course['photo'] = $image;  
          }
         if(empty($id)) { 
         $this->db->insert('courses', $course);
         $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Added Successfully</small></div>');
         } else {
         if(empty($_FILES['main_image']['name'])) {
         $course['photo'] = $this->input->post('ext_photo');     
         }     
         $this->db->where('id', $id)->update('courses', $course);
         $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Updated Successfully</small></div>');    
         }    
         redirect('admin/courses');     
      }  
    }
    public function list_courses()
    {
     
      $limit = $this->input->post('length');
	  $start = $this->input->post('start');  
	  
      $totalData = $this->crud_model->allcourses_count();

		        $totalFiltered = $totalData;

		        if(empty($this->input->post('search')['value']))
		        {
                   
                      $courses = $this->crud_model->allcourses($limit,$start); 
		        	
		        }
		        else {
		            $search = $this->input->post('search')['value'];

		            $courses =  $this->crud_model->course_search($limit,$start,$search);

		            $totalFiltered = $this->crud_model->course_search_count($search);
		        }

		        $data = array();
                $no = $this->input->post('start');
		        if(!empty($courses))
		        {
		        	
		            foreach ($courses as $course)
		            {   
                        $no++;
                        $content = strip_tags($course->content);
                        
                      
                        $nestedData['#'] = $no ;
                        $nestedData['title'] = $course->title ;
                        $nestedData['content'] = $content ;
                        $nestedData['photo'] = "<a target='_blank' href='".base_url()."uploads/front/courses/".$course->photo."'><img alt='image' src='".base_url()."uploads/front/courses/".$course->photo."' class='' width='45'></a>";
                        $nestedData['options'] = "<a href='".base_url()."admin/add_courses/".$course->id."' class='add-tooltip' data-toggle='tooltip' data-placement='top' title='Edit' ><i class='far fa-edit' style='font-size: 1.5em'></i></a><a class='add-tooltip' data-toggle='tooltip' data-placement='top' title='Delete' ><i data-target='#delete_modal".$course->id."' data-toggle='modal' class='fas fa-trash-alt' style='font-size: 1.5em'></i></a>";
                        
		                $data[] = $nestedData;
		            }
		        }

		        $json_data = array(
		                    "draw"            => intval($this->input->post('draw')),
		                    "recordsTotal"    => intval($totalData),
		                    "recordsFiltered" => intval($totalFiltered),
		                    "data"            => $data
		                    );
		        echo json_encode($json_data);
    }
    public function delete_course($id)
    {
         
    $this->db->where('id', $id);
    $result = $this->db->delete('courses');
    if ($result) {
     $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Deleted Successfully</small></div>');
     redirect('admin/courses');    
    } else {
    $this->session->set_flashdata('msg', '<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Error ! Cannot delete the record</small></div>');
     redirect('admin/courses');    
    }
    }
    public function list_course_pages()
    {
     
      $limit = $this->input->post('length');
	  $start = $this->input->post('start');  
	  
      $totalData = $this->crud_model->allcourse_details_count();

		        $totalFiltered = $totalData;

		        if(empty($this->input->post('search')['value']))
		        {
                   
                      $courses = $this->crud_model->allcourse_details($limit,$start); 
		        	
		        }
		        else {
		            $search = $this->input->post('search')['value'];

		            $courses =  $this->crud_model->course_details_search($limit,$start,$search);

		            $totalFiltered = $this->crud_model->course_details_search_count($search);
		        }

		        $data = array();
                $no = $this->input->post('start');
		        if(!empty($courses))
		        {
		        	
		            foreach ($courses as $course)
		            {   
                        $category = $this->db->get_where('prepare_category', array('id'=>$course->category))->row(); 
                        $no++;
                        $description = strip_tags($course->description);
                        $features = strip_tags($course->features);
                      
                        $nestedData['#'] = $no ;
                        $nestedData['category'] = $category->name ;
                        $nestedData['description'] = $description ;
                        $nestedData['features'] = $features ;
                         $nestedData['banner'] = "<a target='_blank' href='".base_url()."uploads/front/banner_image/".$course->banner."'><img alt='image' src='".base_url()."uploads/front/banner_image/".$course->banner."' class='' width='45'></a>";
                        $nestedData['photo'] = "<a target='_blank' href='".base_url()."uploads/front/courses/".$course->sec_image."'><img alt='image' src='".base_url()."uploads/front/courses/".$course->sec_image."' class='' width='45'></a>";
                        $nestedData['options'] = "<a href='".base_url()."admin/add_course_pages/".$course->id."' class='add-tooltip' data-toggle='tooltip' data-placement='top' title='Edit' ><i class='far fa-edit' style='font-size: 1.5em'></i></a><a class='add-tooltip' data-toggle='tooltip' data-placement='top' title='Delete' ><i data-target='#delete_modal".$course->id."' data-toggle='modal' class='fas fa-trash-alt' style='font-size: 1.5em'></i></a>";
                        
		                $data[] = $nestedData;
		            }
		        }

		        $json_data = array(
		                    "draw"            => intval($this->input->post('draw')),
		                    "recordsTotal"    => intval($totalData),
		                    "recordsFiltered" => intval($totalFiltered),
		                    "data"            => $data
		                    );
		        echo json_encode($json_data);
    }
    public function delete_course_details_page($id)
    {
         
    $this->db->where('id', $id);
    $result = $this->db->delete('course_page');
    if ($result) {
     $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Deleted Successfully</small></div>');
     redirect('admin/manage_category_pages');    
    } else {
    $this->session->set_flashdata('msg', '<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Error ! Cannot delete the record</small></div>');
     redirect('admin/manage_category_pages');    
    }
    }
    public function statistics()
    {
      $data['title']    = "Statistics";
      $data['page_name']    = "statistics";
      $data['statistics_data']   = $this->db->get_where('statistics', array('id'=>'1'))->row(); 
      $this->load->view('back/statistics.php' , $data);
    }
    public function do_add_statistics($id ='')
    {
      $data['title']    = "Add Statistics";
      $data['page_name']    = "do_add_statistics"; 
      if($_POST){    
        $statistics = array(
            'courses'     => $this->input->post('courses'),
            'teachers'    => $this->input->post('teachers'),
            'followers'    => $this->input->post('followers'),
            'students'    => $this->input->post('students'),
           ); 
        
         if(empty($id)) {  
         $this->db->insert('statistics', $statistics);
         $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Added Successfully</small></div>');
         } else {     
         $this->db->where('id', $id)->update('statistics', $statistics);
         $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Updated Successfully</small></div>');    
         }    
         redirect('admin/statistics');     
      }  
    }
    public function welcome()
    {
      $data['title']    = "Welcome";
      $data['page_name']    = "welcome";
      $data['welcome_data']   = $this->db->get_where('welcome', array('id'=>'1'))->row(); 
      $this->load->view('back/welcome.php' , $data);
    }
     public function do_add_welcome($id ='')
    {
      $data['title']    = "Add Welcome";
      $data['page_name']    = "do_add_welcome"; 
      if($_POST){
      $status = '1';  
     // if($this->input->post('status')) $status = '1';    
        $welcome = array(
            'title'     => $this->input->post('title'),
            'content'    => $this->input->post('textarea1'),
           // 'status'    => $status,
           ); 
          //main pic upload   
           
         $config['upload_path'] = './uploads/front/welcome/';
        // $config['allowed_types'] = 'docx|docs|txt|pdf|xls|JPG|jpg|png|jpeg';
         $config['allowed_types'] = '*';
         $config['encrypt_name']=true;
         $this->load->library('upload', $config);
         $this->upload->initialize($config);  
           
         $img = "main_image";
         
         if (! empty($_FILES['main_image']['name']) && ! $this->upload->do_upload($img))
          {
          $this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Please Upload a Valid Photo</div>');
            redirect('admin/welcome');
          } else {
           
          $data = array('upload_data' => $this->upload->data());

          $field_data = $this->upload->data();
          $image = $field_data['file_name']; 
          $welcome['photo'] = $image;  
          }
         if(empty($id)) {  
         $this->db->insert('welcome', $welcome);
         $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Added Successfully</small></div>');
         } else {
         if(empty($_FILES['main_image']['name'])) {
         $welcome['photo'] = $this->input->post('ext_photo');     
         }     
         $this->db->where('id', $id)->update('welcome', $welcome);
         $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Updated Successfully</small></div>');    
         }    
         redirect('admin/welcome');     
      }  
    }
      public function about_us()
    {
      $data['title']    = "About Us";
      $data['page_name']    = "about_us";
      $data['about_data']   = $this->db->get_where('about_us', array('id'=>'1'))->row(); 
      $this->load->view('back/about.php' , $data);
    }
     public function do_add_about($id ='')
    {
      $data['title']    = "Add About Us";
      $data['page_name']    = "do_add_about"; 
      if($_POST){  
        $welcome = array(
           ); 
          //main pic upload   
           
         $config['upload_path'] = './uploads/front/banner_image/';
        // $config['allowed_types'] = 'docx|docs|txt|pdf|xls|JPG|jpg|png|jpeg';
         $config['allowed_types'] = '*';
         $config['encrypt_name']=true;
         $this->load->library('upload', $config);
         $this->upload->initialize($config);  
           
         $img = "main_image";
         
         if (! empty($_FILES['main_image']['name']) && ! $this->upload->do_upload($img))
          {
          $this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Please Upload a Valid Photo</div>');
            redirect('admin/about_us');
          } else {
           
          $data = array('upload_data' => $this->upload->data());

          $field_data = $this->upload->data();
          $image = $field_data['file_name']; 
          $welcome['photo'] = $image;  
          }
         if(empty($id)) {  
         $this->db->insert('about_us', $welcome);
         $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Added Successfully</small></div>');
         } else {
         if(empty($_FILES['main_image']['name'])) {
         $welcome['photo'] = $this->input->post('ext_photo');     
         }     
         $this->db->where('id', $id)->update('about_us', $welcome);
         $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Updated Successfully</small></div>');    
         }    
         redirect('admin/about_us');     
      }  
    }
     public function banner()
    {
      $data['title']    = "Banner";
      $data['page_name']    = "banner";
      $this->load->view('back/banner.php' , $data);
    }
    
     public function add_banner($id='')
    {
      if(empty($id)) {
      $data['title']    = "Add Banner";
      $data['page_name']    = "add_banner"; 
      } else {
      $data['title']     = "Edit Banner";
      $data['page_name'] = "edit_banner";
      $data['banner_data']   = $this->db->get_where('banner', array('id'=>$id))->row();    
      } 
      $this->load->view('back/add_banner.php' , $data); 
    }
    public function do_add_banner($id ='')
    {
      $data['title']    = "Add Banner";
      $data['page_name']    = "do_add_banner"; 
      if($_POST){
      $status = '1';  
     // if($this->input->post('status')) $status = '1';    
        $banner = array(
            'title'     => $this->input->post('title'),
            'content'    => $this->input->post('textarea1'),
            'status'    => $status,
           ); 
          //main pic upload   
           
         $config['upload_path'] = './uploads/front/banner_image/';
        // $config['allowed_types'] = 'docx|docs|txt|pdf|xls|JPG|jpg|png|jpeg';
         $config['allowed_types'] = '*';
         $config['encrypt_name']=true;
         $this->load->library('upload', $config);
         $this->upload->initialize($config);  
           
         $img = "main_image";
         
         if (! empty($_FILES['main_image']['name']) && ! $this->upload->do_upload($img))
          {
          $this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Please Upload a Valid Photo</div>');
            redirect('admin/add_banner');
          } else {
           
          $data = array('upload_data' => $this->upload->data());

          $field_data = $this->upload->data();
          $image = $field_data['file_name']; 
          $banner['photo'] = $image;  
          }
         if(empty($id)) { 
         $banner['date_created'] = time(); 
         $this->db->insert('banner', $banner);
         $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Added Successfully</small></div>');
         } else {
         if(empty($_FILES['main_image']['name'])) {
         $banner['photo'] = $this->input->post('ext_photo');     
         }     
         $this->db->where('id', $id)->update('banner', $banner);
         $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Updated Successfully</small></div>');    
         }    
         redirect('admin/banner');     
      }  
    }
    public function list_banner()
    {
     
      $limit = $this->input->post('length');
	  $start = $this->input->post('start');  
	  
      $totalData = $this->crud_model->allbanners_count();

		        $totalFiltered = $totalData;

		        if(empty($this->input->post('search')['value']))
		        {
                   
                      $banners = $this->crud_model->allbanners($limit,$start); 
		        	
		        }
		        else {
		            $search = $this->input->post('search')['value'];

		            $banners =  $this->crud_model->banner_search($limit,$start,$search);

		            $totalFiltered = $this->crud_model->banner_search_count($search);
		        }

		        $data = array();
                $no = $this->input->post('start');
		        if(!empty($banners))
		        {
		        	
		            foreach ($banners as $banner)
		            {   
                        $no++;
                        $date = $banner->date_created;
                        $date_created = date("d-m-Y", $date);
                        $banner_status = $banner->status;
                        $content = strip_tags($banner->content);
                        
                        if($banner_status == '1') {
                        $status      = "<i class='fas fa-check-circle' style='font-size: 1.3em;color:green;'></i>"; } else {
                        $status      = "<i class='fas fa-times-circle' style='font-size: 1.3em;color:red;'></i>"; }
                        $nestedData['#'] = $no ;
                        $nestedData['title'] = $banner->title ;
                        $nestedData['content'] = $content ;
                        $nestedData['photo'] = "<a target='_blank' href='".base_url()."uploads/front/banner_image/".$banner->photo."'><img alt='image' src='".base_url()."uploads/front/banner_image/".$banner->photo."' class='' width='45'></a>";
                        $nestedData['options'] = "<a href='".base_url()."admin/add_banner/".$banner->id."' class='add-tooltip' data-toggle='tooltip' data-placement='top' title='Edit' ><i class='far fa-edit' style='font-size: 1.5em'></i></a><a class='add-tooltip' data-toggle='tooltip' data-placement='top' title='Delete' ><i data-target='#delete_modal".$banner->id."' data-toggle='modal' class='fas fa-trash-alt' style='font-size: 1.5em'></i></a>";
                        
		                $data[] = $nestedData;
		            }
		        }

		        $json_data = array(
		                    "draw"            => intval($this->input->post('draw')),
		                    "recordsTotal"    => intval($totalData),
		                    "recordsFiltered" => intval($totalFiltered),
		                    "data"            => $data
		                    );
		        echo json_encode($json_data);
    }
    public function delete_banner($id)
    {
         
    $this->db->where('id', $id);
    $result = $this->db->delete('banner');
    if ($result) {
     $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Deleted Successfully</small></div>');
     redirect('admin/banner');    
    } else {
    $this->session->set_flashdata('msg', '<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Error ! Cannot delete the record</small></div>');
     redirect('admin/banner');    
    }
    }
    public function call_back()
    {
      $data['title']    = "Call Back List";
      $data['page_name']    = "call_back_list";
      $this->load->view('back/call_back.php' , $data);
    }
    public function list_calls()
    {
     
      $limit = $this->input->post('length');
	  $start = $this->input->post('start');  
	  
      $totalData = $this->crud_model->allcalls_count();

		        $totalFiltered = $totalData;

		        if(empty($this->input->post('search')['value']))
		        {
                   
                      $datas = $this->crud_model->allcalls($limit,$start); 
		        	
		        }
		        else {
		            $search = $this->input->post('search')['value'];

		            $datas =  $this->crud_model->call_search($limit,$start,$search);

		            $totalFiltered = $this->crud_model->call_search_count($search);
		        }

		        $data = array();
                $no = $this->input->post('start');
		        if(!empty($datas))
		        {
		        	
		            foreach ($datas as $det)
		            {   
                        $no++;
                        $date = $det->date_created;
                        $date_created = date("d-m-Y", $date);
                        $nestedData['#'] = $no ;
                        $nestedData['mobile'] = $det->phone ;
                        $nestedData['date'] = $date_created ;
                        $nestedData['options'] = "<a class='add-tooltip' data-toggle='tooltip' data-placement='top' title='Delete' ><i data-target='#delete_modal".$det->id."' data-toggle='modal' class='fas fa-trash-alt' style='font-size: 1.5em'></i></a>";
                        
		                $data[] = $nestedData;
		            }
		        }

		        $json_data = array(
		                    "draw"            => intval($this->input->post('draw')),
		                    "recordsTotal"    => intval($totalData),
		                    "recordsFiltered" => intval($totalFiltered),
		                    "data"            => $data
		                    );
		        echo json_encode($json_data);
    }
    public function delete_call_data($id)
    {
         
    $this->db->where('id', $id);
    $result = $this->db->delete('call_back');
    if ($result) {
     $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Deleted Successfully</small></div>');
     redirect('admin/call_back');    
    } else {
    $this->session->set_flashdata('msg', '<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Error ! Cannot delete the record</small></div>');
     redirect('admin/call_back');    
    }
    }
    public function acca_enquiry()
    {
      $data['title']    = "ACCA Enquiry";
      $data['page_name']    = "acca_enquiry";
      $this->load->view('back/acca_enquiry.php' , $data);
    }
    public function list_acca_enquiry()
    {
     
      $limit = $this->input->post('length');
	  $start = $this->input->post('start');  
	  
      $totalData = $this->crud_model->acca_allapplicants_count();

		        $totalFiltered = $totalData;

		        if(empty($this->input->post('search')['value']))
		        {
                   
                      $datas = $this->crud_model->acca_allapplicants($limit,$start); 
		        	
		        }
		        else {
		            $search = $this->input->post('search')['value'];

		            $datas =  $this->crud_model->acca_applicant_search($limit,$start,$search);

		            $totalFiltered = $this->crud_model->acca_applicant_search_count($search);
		        }

		        $data = array();
                $no = $this->input->post('start');
		        if(!empty($datas))
		        {
		        	
		            foreach ($datas as $det)
		            {   
                        $no++;
                        $date = $det->date;
                       // $date_created = date("d-m-Y", $date);
                        $nestedData['#'] = $no ;
                        $nestedData['name'] = $det->name ;
                        $nestedData['email'] = $det->email ;
                        $nestedData['mobile'] = $det->phone ;
                        $nestedData['test_name'] = $det->test_name ;
                        $nestedData['message'] = $det->message ;
                        $nestedData['date'] = $date ;
                        $nestedData['options'] = "<a class='add-tooltip' data-toggle='tooltip' data-placement='top' title='Delete' ><i data-target='#delete_modal".$det->id."' data-toggle='modal' class='fas fa-trash-alt' style='font-size: 1.5em'></i></a>";
                        
		                $data[] = $nestedData;
		            }
		        }

		        $json_data = array(
		                    "draw"            => intval($this->input->post('draw')),
		                    "recordsTotal"    => intval($totalData),
		                    "recordsFiltered" => intval($totalFiltered),
		                    "data"            => $data
		                    );
		        echo json_encode($json_data);
    }
    public function applications()
    {
      $data['title']    = "Enquiries";
      $data['page_name']    = "enquiries";
      $this->load->view('back/applications.php' , $data);
    }
    public function list_applicants()
    {
     
      $limit = $this->input->post('length');
	  $start = $this->input->post('start');  
	  
      $totalData = $this->crud_model->allapplicants_count();

		        $totalFiltered = $totalData;

		        if(empty($this->input->post('search')['value']))
		        {
                   
                      $datas = $this->crud_model->allapplicants($limit,$start); 
		        	
		        }
		        else {
		            $search = $this->input->post('search')['value'];

		            $datas =  $this->crud_model->applicant_search($limit,$start,$search);

		            $totalFiltered = $this->crud_model->applicant_search_count($search);
		        }

		        $data = array();
                $no = $this->input->post('start');
		        if(!empty($datas))
		        {
		        	
		            foreach ($datas as $det)
		            {   
                        $no++;
                        $date = $det->date_created;
                       // $date_created = date("d-m-Y", $date);
                        $nestedData['#'] = $no ;
                        $nestedData['name'] = $det->name ;
                        $nestedData['email'] = $det->email ;
                        $nestedData['mobile'] = $det->phone ;
                        $nestedData['course'] = $det->course ;
                        $nestedData['message'] = $det->message ;
                        $nestedData['date'] = $date ;
                        $nestedData['options'] = "<a class='add-tooltip' data-toggle='tooltip' data-placement='top' title='Delete' ><i data-target='#delete_modal".$det->id."' data-toggle='modal' class='fas fa-trash-alt' style='font-size: 1.5em'></i></a>";
                        
		                $data[] = $nestedData;
		            }
		        }

		        $json_data = array(
		                    "draw"            => intval($this->input->post('draw')),
		                    "recordsTotal"    => intval($totalData),
		                    "recordsFiltered" => intval($totalFiltered),
		                    "data"            => $data
		                    );
		        echo json_encode($json_data);
    }
    public function delete_applicant($id)
    {
         
    $this->db->where('id', $id);
    $result = $this->db->delete('applications');
    if ($result) {
     $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Deleted Successfully</small></div>');
     redirect('admin/applications');    
    } else {
    $this->session->set_flashdata('msg', '<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Error ! Cannot delete the record</small></div>');
     redirect('admin/applications');    
    }
    }
    public function delete_acca_enquiry($id)
    {
         
    $this->db->where('id', $id);
    $result = $this->db->delete('acca_enquiry');
    if ($result) {
     $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Deleted Successfully</small></div>');
     redirect('admin/acca_enquiry');    
    } else {
    $this->session->set_flashdata('msg', '<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Error ! Cannot delete the record</small></div>');
     redirect('admin/acca_enquiry');    
    }
    }
    public function brochure()
    {
      $data['title']    = "Brochure Downloads";
      $data['page_name']    = "brochure_downloads";
      $data['business_profile']    = $this->db->get_where('business_profile', array('id'=>'1'))->row();
      $this->load->view('back/brochure.php' , $data);
    }
    public function list_brochureDownloads()
    {
     
      $limit = $this->input->post('length');
	  $start = $this->input->post('start');  
	  
      $totalData = $this->crud_model->alldownloads_count();

		        $totalFiltered = $totalData;

		        if(empty($this->input->post('search')['value']))
		        {
                   
                      $datas = $this->crud_model->alldownloads($limit,$start); 
		        	
		        }
		        else {
		            $search = $this->input->post('search')['value'];

		            $datas =  $this->crud_model->download_search($limit,$start,$search);

		            $totalFiltered = $this->crud_model->download_search_count($search);
		        }

		        $data = array();
                $no = $this->input->post('start');
		        if(!empty($datas))
		        {
		        	
		            foreach ($datas as $det)
		            {   
                        $no++;
                        $date = $det->date_created;
                        $date_created = date("d-m-Y", $date);
                        $nestedData['#'] = $no ;
                        $nestedData['name'] = $det->first_name." ".$det->last_name ;
                        $nestedData['email'] = $det->email ;
                        $nestedData['mobile'] = $det->phone ;
                        $nestedData['date'] = $date_created ;
                        $nestedData['options'] = "<a class='add-tooltip' data-toggle='tooltip' data-placement='top' title='Delete' ><i data-target='#delete_modal".$det->id."' data-toggle='modal' class='fas fa-trash-alt' style='font-size: 1.5em'></i></a>";
                        
		                $data[] = $nestedData;
		            }
		        }

		        $json_data = array(
		                    "draw"            => intval($this->input->post('draw')),
		                    "recordsTotal"    => intval($totalData),
		                    "recordsFiltered" => intval($totalFiltered),
		                    "data"            => $data
		                    );
		        echo json_encode($json_data);
    }
    public function delete_brochureDownloader($id)
    {
         
    $this->db->where('id', $id);
    $result = $this->db->delete('download_brochure');
    if ($result) {
     $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Deleted Successfully</small></div>');
     redirect('admin/brochure');    
    } else {
    $this->session->set_flashdata('msg', '<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Error ! Cannot delete the record</small></div>');
     redirect('admin/brochure');    
    }
    }
    public function upload_brochure()
    {
         $brochure = array(); 
          
         $config['upload_path'] = './uploads/front/brochure/';
        // $config['allowed_types'] = 'docx|docs|txt|pdf|xls|JPG|jpg|png|jpeg';
         $config['allowed_types'] = '*';
         $config['encrypt_name']=true;
         $this->load->library('upload', $config);
         $this->upload->initialize($config);  
           
         $img = "brochure";
         
         if (! empty($_FILES['brochure']['name']) && ! $this->upload->do_upload($img))
          {
          $this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Please Upload a Valid File</div>');
            redirect('admin/brochure');
          } else {
           
          $data = array('upload_data' => $this->upload->data());

          $field_data = $this->upload->data();
          $image = $field_data['file_name']; 
          $brochure['brochure'] = $image;
          }
         $this->db->where('id', '1')->update('business_profile', $brochure); 
        // $this->db->insert('business_profile', $brochure);
         $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Added Successfully</small></div>');
         redirect('admin/brochure');  
    }
    public function contacts()
    {
      $data['title']    = "Messages";
      $data['page_name']    = "messages";
      $this->load->view('back/contacts.php' , $data);
    }
    public function list_contacts()
    {
     
      $limit = $this->input->post('length');
	  $start = $this->input->post('start');  
	  
      $totalData = $this->crud_model->allcontacts_count();

		        $totalFiltered = $totalData;

		        if(empty($this->input->post('search')['value']))
		        {
                   
                      $contacts = $this->crud_model->allcontacts($limit,$start); 
		        	
		        }
		        else {
		            $search = $this->input->post('search')['value'];

		            $contacts =  $this->crud_model->contacts_search($limit,$start,$search);

		            $totalFiltered = $this->crud_model->contacts_search_count($search);
		        }

		        $data = array();
                $no = $this->input->post('start');
		        if(!empty($contacts))
		        {
		        	
		            foreach ($contacts as $contact)
		            {   
                        $no++;
                        $date = $contact->date_created;
                        $date_created = date("d-m-Y", $date);
                        $nestedData['#'] = $no ;
                        $nestedData['name'] = $contact->name ;
                        $nestedData['email'] = $contact->email ;
                        $nestedData['phone'] = $contact->phone ;
                        $nestedData['message'] = $contact->message ;
                        $nestedData['date'] = $date_created ;
                        $nestedData['options'] = "<a class='add-tooltip' data-toggle='tooltip' data-placement='top' title='Delete' ><i data-target='#delete_modal".$contact->id."' data-toggle='modal' class='far fa-trash-alt' style='font-size: 1.5em'></i></a>";
                        
		                $data[] = $nestedData;
		            }
		        }

		        $json_data = array(
		                    "draw"            => intval($this->input->post('draw')),
		                    "recordsTotal"    => intval($totalData),
		                    "recordsFiltered" => intval($totalFiltered),
		                    "data"            => $data
		                    );
		        echo json_encode($json_data);
    }
    public function delete_message($id)
    {
         
    $this->db->where('id', $id);
    $result = $this->db->delete('contact_us');
    if ($result) {
     $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Deleted Successfully</small></div>');
     redirect('admin/contacts');    
    } else {
    $this->session->set_flashdata('msg', '<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Error ! Cannot delete the record</small></div>');
     redirect('admin/contacts');    
    }
    }
     public function offers()
    {
      $data['title']    = "Offers";
      $data['page_name']    = "offers";
      $this->load->view('back/offers.php' , $data);
    }
    public function list_offers()
    {
     
      $limit = $this->input->post('length');
	  $start = $this->input->post('start');  
	  
      $totalData = $this->crud_model->alloffers_count();

		        $totalFiltered = $totalData;

		        if(empty($this->input->post('search')['value']))
		        {
                   
                      $offers = $this->crud_model->alloffers($limit,$start); 
		        	
		        }
		        else {
		            $search = $this->input->post('search')['value'];

		            $offers =  $this->crud_model->offer_search($limit,$start,$search);

		            $totalFiltered = $this->crud_model->offer_search_count($search);
		        }

		        $data = array();
                $no = $this->input->post('start');
		        if(!empty($offers))
		        {
		        	
		            foreach ($offers as $offer)
		            {   
                        $no++;
                        $date = $offer->date_created;
                        $date_created = date("d-m-Y", $date);
                        $nestedData['#'] = $no ;
                        $nestedData['name'] = $offer->name ;
                        $nestedData['photo'] = "<a target='_blank' href='".base_url()."uploads/front/certifications/".$offer->photo."'><img alt='image' src='".base_url()."uploads/front/certifications/".$offer->photo."' class='' width='45'></a>";
                        $nestedData['options'] = "<a class='add-tooltip' data-toggle='tooltip' data-placement='top' title='Delete' ><i data-target='#delete_modal".$offer->id."' data-toggle='modal' class='fas fa-trash-alt' style='font-size: 1.5em'></i></a>";
                        
		                $data[] = $nestedData;
		            }
		        }

		        $json_data = array(
		                    "draw"            => intval($this->input->post('draw')),
		                    "recordsTotal"    => intval($totalData),
		                    "recordsFiltered" => intval($totalFiltered),
		                    "data"            => $data
		                    );
		        echo json_encode($json_data);
    }
    public function delete_offer($id)
    {
         
    $this->db->where('id', $id);
    $result = $this->db->delete('offers');
    if ($result) {
     $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Deleted Successfully</small></div>');
     redirect('admin/offers');    
    } else {
    $this->session->set_flashdata('msg', '<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Error ! Cannot delete the record</small></div>');
     redirect('admin/offers');    
    }
    }
      public function add_offer()
    {
      
      if($_POST){
        $name = $this->input->post('name');
        $cer_data = array(
            'name'     => $this->input->post('name'),
            'date_created'       => time(),
           ); 
          
          //pic upload   
           
         $config['upload_path'] = './uploads/front/certifications/';
        // $config['allowed_types'] = 'docx|docs|txt|pdf|xls|JPG|jpg|png|jpeg';
         $config['allowed_types'] = '*';
         $config['encrypt_name']=true;
         $this->load->library('upload', $config);
         $this->upload->initialize($config);  
           
         $img = "offer";
         
         if (! empty($_FILES['offer']['name']) && ! $this->upload->do_upload($img))
          {
          $this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Please Upload a Valid Photo</div>');
            redirect('admin/offers');
          } else {
           
          $data = array('upload_data' => $this->upload->data());

          $field_data = $this->upload->data();
          $image = $field_data['file_name']; 
          $cer_data['photo'] = $image;
          }
          
         $this->db->insert('offers', $cer_data);
         $this->session->set_flashdata('msg', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><span class="icon icon-warning-circle icon-lg"></span><small>Added Successfully</small></div>');
         redirect('admin/offers');
      }  
    }
    public function logout()
    {
        $this->login->logout();
        redirect('login');
    }
    /////////////////////////////////////////////////////////////////
    
   
    
}
