<?php

namespace App\Controllers\Admin;

use App\Controllers\BaseController;
use App\Models\SettingModel;
use App\Models\MainpageModel;
use App\Models\UploadModel;
use App\Models\HomeModel;

class MainpageSetting extends BaseController
{
    public function get_all_home_slider()
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['all_home_slider'] = $home->get_all_slider();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/view_home_slider');
        echo view('admin/include/footer');
    }

    function add_new_slider()
    {
        $setting = new SettingModel();
        $data['app_setting'] = $setting->get_application_setting();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/add_new_slider');
        echo view('admin/include/footer');
    }
    function new_slider_add()
    {
        $home = new MainpageModel();
        $upload = new UploadModel();
        $data['slider_heading']      =  $this->request->getVar('slider_heading');
        $data['slider_sub_heading']      =  $this->request->getVar('slider_sub_heading');
        $data['slider_description']       =  $this->request->getVar('slider_description');
        $data['slider_btn_name']       =  $this->request->getVar('slider_btn_name');
        $data['slider_btn_link']       =  $this->request->getVar('slider_btn_link');
        $data['slider_status']    =  1;
        $data['slider_language']            =  $this->request->getVar('slider_language');
        if($this->request->getFile('slider_image')->isValid() && !$this->request->getFile('slider_image')->hasMoved())
        {
            $data['slider_image'] = $upload->upload_image($this->request->getFile('slider_image'));
        }
        if($home->new_slider_add($data))
        {
            session()->set('success', "Slider Successfully Added");
            return redirect()->to('admin/main_page_setting/slider');
        }
        else
        {
            session()->set('error', "Slider Added Failed");
            return redirect()->to('admin/main_page_setting/slider');
        }
    }

    function edit_slider($id)
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['slider'] = $home->get_slider_by_id($id);
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/edit_slider');
        echo view('admin/include/footer');
    }

    function update_slider($id)
    {
        $home = new MainpageModel();
        $upload = new UploadModel();
        $data['slider_heading']             =  $this->request->getVar('slider_heading');
        $data['slider_sub_heading']         =  $this->request->getVar('slider_sub_heading');
        $data['slider_description']         =  $this->request->getVar('slider_description');
        $data['slider_btn_name']            =  $this->request->getVar('slider_btn_name');
        $data['slider_btn_link']            =  $this->request->getVar('slider_btn_link');
        $data['slider_language']            =  $this->request->getVar('slider_language');
        $slider_img = $home->get_slider_by_id($id);
        if($this->request->getFile('slider_image')->isValid() && !$this->request->getFile('slider_image')->hasMoved())
        {
            if (file_exists(substr($slider_img->slider_image, 1))) {
                unlink(substr($slider_img->slider_image, 1));
            }
            $data['slider_image'] = $upload->upload_image($this->request->getFile('slider_image'));
        }
        if($home->update_slider($data, $id))
        {
            session()->set('success', "Slider Successfully Updated");
            return redirect()->to('admin/main_page_setting/slider');
        }
        else
        {
            session()->set('error', "Slider Updated Failed");
            return redirect()->to('admin/main_page_setting/slider');
        }
    }

    function delete_slider($id)
    {
        $home = new MainpageModel();
        $slider_img = $home->get_slider_by_id($id);
        if (file_exists(substr($slider_img->slider_image, 1))) {
                unlink(substr($slider_img->slider_image, 1));
            }
        if($home->delete_slider($id))
        {
            session()->set('success', "Slider Successfully Deleted");
            return redirect()->to('admin/main_page_setting/slider');
        }
        else
        {
            session()->set('error', "Slider Deleted Failed");
            return redirect()->to('admin/main_page_setting/slider');
        }
    }

    function change_status($id, $status)
    {
        $home = new MainpageModel();
        $data['slider_status'] = $status;
        if($home->change_status($data, $id))
        {
            session()->set('success', "Slider Staus Successfully Changed");
            return redirect()->to('admin/main_page_setting/slider');
        }
        else
        {
            session()->set('error', "Slider Deleted Failed");
            return redirect()->to('admin/main_page_setting/slider');
        }
    }

    public function get_all_slider_stats()
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['all_home_slider_stats'] = $home->get_all_slider_stats();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/all_slider_stats');
        echo view('admin/include/footer');
    }

    function add_new_slider_stats()
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/add_slider_stats');
        echo view('admin/include/footer');
    }

    function new_slider_stats_add()
    {
        $home = new MainpageModel();
        $data['slider_stats_title']      =  $this->request->getVar('slider_stats_title');
        $data['slider_stats_description']      =  $this->request->getVar('slider_stats_description');
        $data['slider_stats_btn_name']       =  $this->request->getVar('slider_stats_btn_name');
        $data['slider_stats_btn_link']       =  $this->request->getVar('slider_stats_btn_link');
        $data['slider_stats_icon']       =  $this->request->getVar('slider_stats_icon');
        if($home->new_slider_stats_add($data))
        {
            session()->set('success', "Stats Successfully Added");
            return redirect()->to('admin/main_page_setting/slider_stats');
        }
        else
        {
            session()->set('error', "Stats Added Failed");
            return redirect()->to('admin/main_page_setting/slider_stats');
        }
    }

    function edit_slider_stats($id)
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['stats'] = $home->get_slider_stats_by_id($id);
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/edit_slider_stats');
        echo view('admin/include/footer');
    }

    function update_slider_stats($id)
    {
        $home = new MainpageModel();
        $data['slider_stats_title']      =  $this->request->getVar('slider_stats_title');
        $data['slider_stats_description']      =  $this->request->getVar('slider_stats_description');
        $data['slider_stats_btn_name']       =  $this->request->getVar('slider_stats_btn_name');
        $data['slider_stats_btn_link']       =  $this->request->getVar('slider_stats_btn_link');
        $data['slider_stats_icon']       =  $this->request->getVar('slider_stats_icon');
        if($home->update_slider_stats($data, $id))
        {
            session()->set('success', "Stats Successfully Updated");
            return redirect()->to('admin/main_page_setting/slider_stats');
        }
        else
        {
            session()->set('error', "Stats Updated Failed");
            return redirect()->to('admin/main_page_setting/slider_stats');
        }
    }

    function delete_slider_stats($id)
    {
        $home = new MainpageModel();
        if($home->delete_slider_stats($id))
        {
            session()->set('success', "Stats Successfully Deleted");
            return redirect()->to('admin/main_page_setting/slider_stats');
        }
        else
        {
            session()->set('error', "Stats Deleted Updated");
            return redirect()->to('admin/main_page_setting/slider_stats');
        }
    }

    

    function update_short_description()
    {
        $home = new MainpageModel();
        $upload = new UploadModel();
        $data['short_about_us_title']             =  $this->request->getVar('short_about_us_title');
        $data['short_about_us_description']         =  $this->request->getVar('short_about_us_description');
        $data['short_about_us_content_title_1']         =  $this->request->getVar('short_about_us_content_title_1');
        $data['short_about_us_content_description_1']            =  $this->request->getVar('short_about_us_content_description_1');
        $data['short_about_us_content_title_2']            =  $this->request->getVar('short_about_us_content_title_2');
        $data['short_about_us_content_description_2']            =  $this->request->getVar('short_about_us_content_description_2');
        $data['short_about_us_content_title_3']            =  $this->request->getVar('short_about_us_content_title_3');
        $data['short_about_us_content_description_3']            =  $this->request->getVar('short_about_us_content_description_3');
        $slider_img = $home->get_shoart_about_us_content();
        if($this->request->getFile('short_about_us_content_image_1')->isValid() && !$this->request->getFile('short_about_us_content_image_1')->hasMoved())
        {
            if (file_exists(substr($slider_img->short_about_us_content_image_1, 1))) {
                unlink(substr($slider_img->short_about_us_content_image_1, 1));
            }
            $data['short_about_us_content_image_1'] = $upload->upload_image($this->request->getFile('short_about_us_content_image_1'));
        }
        if($this->request->getFile('short_about_us_content_image_2')->isValid() && !$this->request->getFile('short_about_us_content_image_2')->hasMoved())
        {
            if (file_exists(substr($slider_img->short_about_us_content_image_2, 1))) {
                unlink(substr($slider_img->short_about_us_content_image_2, 1));
            }
            $data['short_about_us_content_image_2'] = $upload->upload_image($this->request->getFile('short_about_us_content_image_2'));
        }
        if($this->request->getFile('short_about_us_content_image_3')->isValid() && !$this->request->getFile('short_about_us_content_image_3')->hasMoved())
        {
            if (file_exists(substr($slider_img->short_about_us_content_image_3, 1))) {
                unlink(substr($slider_img->short_about_us_content_image_3, 1));
            }
            $data['short_about_us_content_image_3'] = $upload->upload_image($this->request->getFile('short_about_us_content_image_3'));
        }

        if($home->update_short_description($data))
        {
            session()->set('success', "Content Successfully Updated");
            return redirect()->to('admin/main_page_setting/short_about_us');
        }
        else
        {
            session()->set('error', "Content Updated Failed");
            return redirect()->to('admin/main_page_setting/short_about_us');
        }
    }

    function all_testimonials()
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['all_testimonials'] = $home->get_all_testimonials();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/all_testimonials');
        echo view('admin/include/footer');
    }

    function add_new_testimonials()
    {
        $setting = new SettingModel();
        $data['app_setting'] = $setting->get_application_setting();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/add_new_testimonials');
        echo view('admin/include/footer');
    }

    function new_testimonials_add()
    {
        $home = new MainpageModel();
        $upload = new UploadModel();
        $data['testi_des'] = $this->request->getVar('testi_des');
        $data['testi_name'] = $this->request->getVar('testi_name');
        $data['testi_extra'] = $this->request->getVar('testi_extra');
        $data['testi_language'] = $this->request->getVar('testi_language');

        if($this->request->getFile('testi_image')->isValid() && !$this->request->getFile('testi_image')->hasMoved())
        {
            $data['testi_image'] = $upload->upload_image($this->request->getFile('testi_image'));
        }
        if($home->new_testimonials_add($data))
        {
            session()->set('success', "Testimonials Successfully Added");
            return redirect()->to('admin/main_page_setting/all_testimonials');
        }
        else
        {
            session()->set('error', "Testimonials Added Failed");
            return redirect()->to('admin/main_page_setting/all_testimonials');
        }
    }

    function edit_testimonials($id)
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['testimonials'] = $home->get_testimonials_by_id($id);
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/edit_testimonials');
        echo view('admin/include/footer');
    }

    function update_testimonials_add($id)
    {
        $home = new MainpageModel();
        $upload = new UploadModel();
        $data['testi_des'] = $this->request->getVar('testi_des');
        $data['testi_name'] = $this->request->getVar('testi_name');
        $data['testi_extra'] = $this->request->getVar('testi_extra');
        $data['testi_language'] = $this->request->getVar('testi_language');

        $page_img = $home->get_testimonials_by_id($id);
        if($this->request->getFile('testi_image')->isValid() && !$this->request->getFile('testi_image')->hasMoved())
        {
            if (file_exists(substr($page_img->testi_image, 1))) {
                unlink(substr($page_img->testi_image, 1));
            }
            $data['testi_image'] = $upload->upload_image($this->request->getFile('testi_image'));
        }

        if($home->update_testimonials_add($data, $id))
        {
            session()->set('success', "Testimonials Successfully Updated");
            return redirect()->to('admin/main_page_setting/all_testimonials');
        }
        else
        {
            session()->set('error', "Testimonials Updated Failed");
            return redirect()->to('admin/main_page_setting/all_testimonials');
        }
    }

    function delete_testimonials($id)
    {
        $home = new MainpageModel();
        $img = $home->get_testimonials_by_id($id);
        if(file_exists(substr($img->testi_image, 1)))
        {
            unlink(substr($img->testi_image, 1));
        }
        if($home->delete_testimonials($id))
        {
            session()->set('success', "Testimonials Successfully Deleted");
            return redirect()->to('admin/main_page_setting/all_testimonials');
        }
        else
        {
            session()->set('error', "Testimonials Deleted Failed");
            return redirect()->to('admin/main_page_setting/all_testimonials');
        }
    }
    function slide_content()
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['all_slide_content'] = $home->get_all_slide_content();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/slider_content');
        echo view('admin/include/footer');
    }

    function add_new_slide_content()
    {
        $setting = new SettingModel();
        $data['app_setting'] = $setting->get_application_setting();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/add_new_slide_content');
        echo view('admin/include/footer');
    }

    function new_slide_content()
    {
        $home = new MainpageModel();
        $upload = new UploadModel();
        $data['slider_content_title'] = $this->request->getVar('slider_content_title');
        $data['slider_content_description'] = $this->request->getVar('slider_content_description');
        
        if($this->request->getFile('slider_content_image')->isValid() && !$this->request->getFile('slider_content_image')->hasMoved())
        {
           
            $data['slider_content_image'] = $upload->upload_image($this->request->getFile('slider_content_image'));
        }

        if($home->new_slide_content($data))
        {
            session()->set('success', "Content Successfully Added");
            return redirect()->to('admin/main_page_setting/slide_content');
        }
        else
        {
            session()->set('error', "Content Added Failed");
            return redirect()->to('admin/main_page_setting/slide_content');
        }
    }

    function edit_slide_content($id)
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['slide_content'] = $home->get_slide_content_by_id($id);
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/edit_slide_content');
        echo view('admin/include/footer');
    }

    function new_slide_content_update($id)
    {
        $home = new MainpageModel();
        $upload = new UploadModel();
        $data['slider_content_title'] = $this->request->getVar('slider_content_title');
        $data['slider_content_description'] = $this->request->getVar('slider_content_description');
        
        $page_img = $home->get_slide_content_by_id($id);
        if($this->request->getFile('slider_content_image')->isValid() && !$this->request->getFile('slider_content_image')->hasMoved())
        {
            if (file_exists(substr($page_img->slider_content_image, 1))) {
                unlink(substr($page_img->slider_content_image, 1));
            }
            $data['slider_content_image'] = $upload->upload_image($this->request->getFile('slider_content_image'));
        }

        if($home->new_slide_content_update($data, $id))
        {
            session()->set('success', "Content Successfully Updated");
            return redirect()->to('admin/main_page_setting/slide_content');
        }
        else
        {
            session()->set('error', "Content Updated Failed");
            return redirect()->to('admin/main_page_setting/slide_content');
        }
    }

    function delete_slide_content($id)
    {
        $home = new MainpageModel();
        $img = $home->get_slide_content_by_id($id);
        if(file_exists(substr($img->slider_content_image, 1)))
        {
            unlink(substr($img->slider_content_image, 1));
        }
        if($home->delete_slide_content($id))
        {
            session()->set('success', "Content Successfully Deleted");
            return redirect()->to('admin/main_page_setting/slide_content');
        }
        else
        {
            session()->set('error', "Content Deleted Failed");
            return redirect()->to('admin/main_page_setting/slide_content');
        }
    }

    function counting_stats()
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['content'] = $home->get_all_counting_stats();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/counting_stats');
        echo view('admin/include/footer');
    }

    function update_counting_stats()
    {
        $home = new MainpageModel();
        $upload = new UploadModel();
        $data['counting_stats_icon_1'] = $this->request->getVar('counting_stats_icon_1');
        $data['counting_stats_number_1'] = $this->request->getVar('counting_stats_number_1');
        $data['counting_stats_title_1'] = $this->request->getVar('counting_stats_title_1');
        $data['counting_stats_icon_2'] = $this->request->getVar('counting_stats_icon_2');
        $data['counting_stats_number_2'] = $this->request->getVar('counting_stats_number_2');
        $data['counting_stats_title_2'] = $this->request->getVar('counting_stats_title_2');
        $data['counting_stats_icon_3'] = $this->request->getVar('counting_stats_icon_3');
        $data['counting_stats_number_3'] = $this->request->getVar('counting_stats_number_3');
        $data['counting_stats_title_3'] = $this->request->getVar('counting_stats_title_3');
        $data['counting_stats_icon_4'] = $this->request->getVar('counting_stats_icon_4');
        $data['counting_stats_number_4'] = $this->request->getVar('counting_stats_number_4');
        $data['counting_stats_title_4'] = $this->request->getVar('counting_stats_title_4');
        $page_img = $home->get_all_counting_stats();
        if($this->request->getFile('counting_stats_bg_image')->isValid() && !$this->request->getFile('counting_stats_bg_image')->hasMoved())
        {
            if (file_exists(substr($page_img->counting_stats_bg_image, 1))) {
                unlink(substr($page_img->counting_stats_bg_image, 1));
            }
            $data['counting_stats_bg_image'] = $upload->upload_image($this->request->getFile('counting_stats_bg_image'));
        }

        if($home->update_counting_stats($data))
        {
            session()->set('success', "Content Successfully Updated");
            return redirect()->to('admin/main_page_setting/counting_stats');
        }
        else
        {
            session()->set('error', "Content Updated Failed");
            return redirect()->to('admin/main_page_setting/counting_stats');
        }
    }

    function latest_case()
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['all_latest_case'] = $home->get_all_latest_case();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/all_latest_case');
        echo view('admin/include/footer');
    }

    function add_new_case()
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/add_new_case');
        echo view('admin/include/footer');
    }

    function new_case_add()
    {
        $home = new MainpageModel();
        $upload = new UploadModel();
        $data['latest_case_title'] = $this->request->getVar('latest_case_title');
        $data['latest_case_slug'] = slug($this->request->getVar('latest_case_title'));
        $data['latest_case_short_description'] = $this->request->getVar('latest_case_short_description');
        $data['latest_case_description'] = $this->request->getVar('latest_case_description');
        
        if($this->request->getFile('latest_case_image')->isValid() && !$this->request->getFile('latest_case_image')->hasMoved())
        {
           
            $data['latest_case_image'] = $upload->upload_image($this->request->getFile('latest_case_image'));
        }

        if($home->new_case_add($data))
        {
            session()->set('success', "Case Successfully Added");
            return redirect()->to('admin/main_page_setting/latest_case');
        }
        else
        {
            session()->set('error', "Case Added Failed");
            return redirect()->to('admin/main_page_setting/latest_case');
        }
    }

    function edit_case($id)
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['case'] = $home->get_latest_case_by_id($id);
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/edit_case');
        echo view('admin/include/footer');
    }

    function update_case($id)
    {
        $home = new MainpageModel();
        $upload = new UploadModel();
        $data['latest_case_title'] = $this->request->getVar('latest_case_title');
        $data['latest_case_slug'] = slug($this->request->getVar('latest_case_title'));
        $data['latest_case_short_description'] = $this->request->getVar('latest_case_short_description');
        $data['latest_case_description'] = $this->request->getVar('latest_case_description');
        $page_img = $home->get_latest_case_by_id($id);
        if($this->request->getFile('latest_case_image')->isValid() && !$this->request->getFile('latest_case_image')->hasMoved())
        {
            if (file_exists(substr($page_img->latest_case_image, 1))) {
                unlink(substr($page_img->latest_case_image, 1));
            }
            $data['latest_case_image'] = $upload->upload_image($this->request->getFile('latest_case_image'));
        }

        if($home->update_case($data, $id))
        {
            session()->set('success', "Case Successfully Updated");
            return redirect()->to('admin/main_page_setting/latest_case');
        }
        else
        {
            session()->set('error', "Case Updated Failed");
            return redirect()->to('admin/main_page_setting/latest_case');
        }
    }

    function delete_case($id)
    {
        $home = new MainpageModel();
        $page_img = $home->get_latest_case_by_id($id);
        if (file_exists(substr($page_img->latest_case_image, 1))) {
            unlink(substr($page_img->latest_case_image, 1));
        }
        if($home->delete_case($id))
        {
            session()->set('success', "Case Successfully Deleted");
            return redirect()->to('admin/main_page_setting/latest_case');
        }
        else
        {
            session()->set('error', "Case Deleted Failed");
            return redirect()->to('admin/main_page_setting/latest_case');
        }
    }
    
    function all_event()
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['all_event'] = $home->get_all_event();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/all_event');
        echo view('admin/include/footer');
    }

    function add_new_event()
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/add_new_event');
        echo view('admin/include/footer');
    }

    function new_event_add()
    {
        $home = new MainpageModel();
        $upload = new UploadModel();
        $data['page_event_title'] = $this->request->getVar('page_event_title');
        $data['page_event_slug'] = slug($this->request->getVar('page_event_title'));
        $data['page_event_date_time'] = $this->request->getVar('page_event_date_time');
        $data['page_event_location'] = $this->request->getVar('page_event_location');
        $data['page_event_short_description'] = $this->request->getVar('page_event_short_description');
        $data['page_event_language'] = $this->request->getVar('page_event_language');
        $data['page_event_description'] = $this->request->getVar('page_event_description');
        if($this->request->getFile('page_event_image')->isValid() && !$this->request->getFile('page_event_image')->hasMoved())
        {
           
            $data['page_event_image'] = $upload->upload_image($this->request->getFile('page_event_image'));
        }

        if($home->new_event_add($data))
        {
            session()->set('success', "Event Successfully Added");
            return redirect()->to('admin/main_page_setting/all_event');
        }
        else
        {
            session()->set('error', "Event Added Failed");
            return redirect()->to('admin/main_page_setting/all_event');
        }
    }

    function edit_event($id)
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['event'] = $home->get_event_by_id($id);
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/edit_event');
        echo view('admin/include/footer');
    }

    function update_event($id)
    {
        $home = new MainpageModel();
        $upload = new UploadModel();
        $data['page_event_title'] = $this->request->getVar('page_event_title');
        $data['page_event_slug'] = slug($this->request->getVar('page_event_title'));
        $data['page_event_date_time'] = $this->request->getVar('page_event_date_time');
        $data['page_event_location'] = $this->request->getVar('page_event_location');
        $data['page_event_short_description'] = $this->request->getVar('page_event_short_description');
        $data['page_event_description'] = $this->request->getVar('page_event_description');
        $data['page_event_language'] = $this->request->getVar('page_event_language');

        $page_img = $home->get_event_by_id($id);
        if($this->request->getFile('page_event_image')->isValid() && !$this->request->getFile('page_event_image')->hasMoved())
        {
            if (file_exists(substr($page_img->page_event_image, 1))) {
                unlink(substr($page_img->page_event_image, 1));
            }
            $data['page_event_image'] = $upload->upload_image($this->request->getFile('page_event_image'));
        }

        if($home->update_event($data, $id))
        {
            session()->set('success', "Event Successfully Updated");
            return redirect()->to('admin/main_page_setting/all_event');
        }
        else
        {
            session()->set('error', "Event Updated Failed");
            return redirect()->to('admin/main_page_setting/all_event');
        }
    }

    function delete_event($id)
    {
        $home = new MainpageModel();
        $page_img = $home->get_event_by_id($id);
        if (file_exists(substr($page_img->page_event_image, 1))) {
            unlink(substr($page_img->page_event_image, 1));
        }
        if($home->delete_event($id))
        {
            session()->set('success', "Event Successfully Deleted");
            return redirect()->to('admin/main_page_setting/all_event');
        }
        else
        {
            session()->set('error', "Event Deleted Failed");
            return redirect()->to('admin/main_page_setting/all_event');
        }
    }

    function gallery()
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['all_gallery'] = $home->get_all_gallery();
        $data['all_category'] = $home->get_all_gallery_category();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/gallery');
        echo view('admin/include/footer');
    }

    function add_gallery_item()
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['all_category'] = $home->get_all_gallery_category();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/add_gallery_item');
        echo view('admin/include/footer');
    }

    function add_new_gallery_item()
    {
        $home = new MainpageModel();
        $upload = new UploadModel();
        $data['gallery_name'] = $this->request->getVar('gallery_name');
        $data['gallery_video'] = $this->request->getVar('gallery_video');
        $data['gallery_mode'] = $this->request->getVar('gallery_mode');
        $data['gallery_category'] = $this->request->getVar('gallery_category');
        if($this->request->getFile('gallery_image')->isValid() && !$this->request->getFile('gallery_image')->hasMoved())
        {
           
            $data['gallery_image'] = $upload->upload_image($this->request->getFile('gallery_image'));
        }

        if($home->add_new_gallery_item($data))
        {
            session()->set('success', "Gallery Successfully Added");
            return redirect()->to('admin/main_page_setting/gallery');
        }
        else
        {
            session()->set('error', "Gallery Added Failed");
            return redirect()->to('admin/main_page_setting/gallery');
        }
    }

    function edit_gallery($id)
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['gallery'] = $home->get_gallery_by_id($id);
        $data['all_category'] = $home->get_all_gallery_category();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/edit_gallery');
        echo view('admin/include/footer');
    }

    function update_gallery_item($id)
    {
        $home = new MainpageModel();
        $upload = new UploadModel();
        $data['gallery_name'] = $this->request->getVar('gallery_name');
        $data['gallery_video'] = $this->request->getVar('gallery_video');
        $data['gallery_mode'] = $this->request->getVar('gallery_mode');
        $data['gallery_category'] = $this->request->getVar('gallery_category');
        $page_img = $home->get_gallery_by_id($id);
        if($this->request->getFile('gallery_image')->isValid() && !$this->request->getFile('gallery_image')->hasMoved())
        {
            if (file_exists(substr($page_img->gallery_image, 1))) {
                unlink(substr($page_img->gallery_image, 1));
            }
            $data['gallery_image'] = $upload->upload_image($this->request->getFile('gallery_image'));
        }

        if($home->update_gallery_item($data, $id))
        {
            session()->set('success', "Gallery Successfully Updated");
            return redirect()->to('admin/main_page_setting/gallery');
        }
        else
        {
            session()->set('error', "Gallery Updated Failed");
            return redirect()->to('admin/main_page_setting/gallery');
        }
    }

    function delete_gallery($id)
    {
        $home = new MainpageModel();
        $page_img = $home->get_gallery_by_id($id);
        if (file_exists(substr($page_img->gallery_image, 1))) {
            unlink(substr($page_img->gallery_image, 1));
        }
        if($home->delete_gallery($id))
        {
            session()->set('success', "Gallery Successfully Deleted");
            return redirect()->to('admin/main_page_setting/gallery');
        }
        else
        {
            session()->set('error', "Gallery Deleted Failed");
            return redirect()->to('admin/main_page_setting/gallery');
        }
    }

    function featured_project()
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['all_project'] = $home->get_all_featured_project();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/all_featured_project');
        echo view('admin/include/footer');
    }

    function add_new_project()
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/add_new_project');
        echo view('admin/include/footer');
    }

    function new_featured_project_add()
    {
        $home = new MainpageModel();
        $upload = new UploadModel();
        $data['project_title'] = $this->request->getVar('project_title');
        $data['project_slug'] = slug($this->request->getVar('project_title'));
        $data['project_short_description'] = $this->request->getVar('project_short_description');
        $data['project_description'] = $this->request->getVar('project_description');
        $data['project_donation_amt'] = $this->request->getVar('project_donation_amt');
        $data['project_show_front'] = $this->request->getVar('project_show_front') == 1 ? 1 : 0;
        $data['project_show_donate_page'] = $this->request->getVar('project_show_donate_page') == 1 ? 1 : 0;
        $data['project_language'] = $this->request->getVar('project_language');
        if($this->request->getFile('project_image')->isValid() && !$this->request->getFile('project_image')->hasMoved())
        {
           
            $data['project_image'] = $upload->upload_image($this->request->getFile('project_image'));
        }

        if($home->new_featured_project_add($data))
        {
            session()->set('success', "Project Successfully Added");
            return redirect()->to('admin/main_page_setting/featured_project');
        }
        else
        {
            session()->set('error', "Project Added Failed");
            return redirect()->to('admin/main_page_setting/featured_project');
        }
    }

    function edit_featured_project($id)
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['project'] = $home->get_all_featured_project_by_id($id);
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/edit_featured_project');
        echo view('admin/include/footer');
    }

    function featured_project_update($id)
    {
        $home = new MainpageModel();
        $upload = new UploadModel();
        $data['project_title'] = $this->request->getVar('project_title');
        $data['project_slug'] = slug($this->request->getVar('project_title'));
        $data['project_short_description'] = $this->request->getVar('project_short_description');
        $data['project_description'] = $this->request->getVar('project_description');
        $data['project_donation_amt'] = $this->request->getVar('project_donation_amt');
        $data['project_show_front'] = $this->request->getVar('project_show_front') == 1 ? 1 : 0;
        $data['project_show_donate_page'] = $this->request->getVar('project_show_donate_page') == 1 ? 1 : 0;
        $data['project_language'] = $this->request->getVar('project_language');
        $page_img = $home->get_all_featured_project_by_id($id);
        if($this->request->getFile('project_image')->isValid() && !$this->request->getFile('project_image')->hasMoved())
        {
            if (file_exists(substr($page_img->project_image, 1))) {
                unlink(substr($page_img->project_image, 1));
            }
            $data['project_image'] = $upload->upload_image($this->request->getFile('project_image'));
        }

        if($home->featured_project_update($data, $id))
        {
            session()->set('success', "Project Successfully Updated");
            return redirect()->to('admin/main_page_setting/featured_project');
        }
        else
        {
            session()->set('error', "Project Updated Failed");
            return redirect()->to('admin/main_page_setting/featured_project');
        }
    }

    function delete_featured_project($id)
    {
        $home = new MainpageModel();
        $page_img = $home->get_all_featured_project_by_id($id);
        if (file_exists(substr($page_img->project_image, 1))) {
            unlink(substr($page_img->project_image, 1));
        }
        if($home->delete_featured_project($id))
        {
            session()->set('success', "Project Successfully Deleted");
            return redirect()->to('admin/main_page_setting/featured_project');
        }
        else
        {
            session()->set('error', "Project Deleted Failed");
            return redirect()->to('admin/main_page_setting/featured_project');
        }
    }

    function became_a_volunteer()
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['eng_data'] = $home->get_all_became_a_volunteer('en');
        $data['hi_data'] = $home->get_all_became_a_volunteer('hi');
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/became_a_volunteer');
        echo view('admin/include/footer');
    }

    function update_became_a_volunteer($lan)
    {
        $home = new MainpageModel();
        $upload = new UploadModel();
        $data['volunteer_image_video'] = $this->request->getVar('volunteer_image_video');
        $data['volunteer_video'] = $this->request->getVar('volunteer_video');
        $data['volunteer_description'] = $this->request->getVar('volunteer_description');
        $page_img = $home->get_all_became_a_volunteer($lan);
        if($this->request->getFile('volunteer_image')->isValid() && !$this->request->getFile('volunteer_image')->hasMoved())
        {
            if (file_exists(substr($page_img->volunteer_image, 1))) {
                unlink(substr($page_img->volunteer_image, 1));
            }
            $data['volunteer_image'] = $upload->upload_image($this->request->getFile('volunteer_image'));
        }

        if($home->update_became_a_volunteer($data, $lan))
        {
            session()->set('success', "Section Successfully Updated");
            return redirect()->to('admin/main_page_setting/became_a_volunteer');
        }
        else
        {
            session()->set('error', "Section Updated Failed");
            return redirect()->to('admin/main_page_setting/became_a_volunteer');
        }
    }

    function heading_sub_heading()
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['data'] = $home->get_heading_sub_heading();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/heading_sub_heading');
        echo view('admin/include/footer');
    }

    function update_heading_sub_heading()
    {
        $home = new MainpageModel();
        $data['featured_project'] = $this->request->getVar('featured_project');
        $data['became_a_volunteer'] = $this->request->getVar('became_a_volunteer');
        $data['events'] = $this->request->getVar('events');
        $data['latest_case'] = $this->request->getVar('latest_case');
        $data['make_a_donation_now'] = $this->request->getVar('make_a_donation_now');
        $data['gallery'] = $this->request->getVar('gallery');
        $data['our_donors_say'] = $this->request->getVar('our_donors_say');
        $data['recent_news'] = $this->request->getVar('recent_news');

        if($home->update_heading_sub_heading($data))
        {
            session()->set('success', "Data Successfully Updated");
            return redirect()->to('admin/main_page_setting/heading_sub_heading');
        }
        else
        {
            session()->set('error', "Data Updated Failed");
            return redirect()->to('admin/main_page_setting/heading_sub_heading');
        }
    }

    function update_about_page_overview_en()
    {
        $home = new MainpageModel();
        $upload = new UploadModel();
        $data['about_title'] = $this->request->getVar('about_title');
        $data['about_content'] = $this->request->getVar('about_content');
        if($home->update_about_page_overview($data, 1))
        {
            session()->set('success', "Section Successfully Updated");
            return redirect()->to('admin/main_page_setting/short_about_us');
        }
        else
        {
            session()->set('error', "Section Updated Failed");
            return redirect()->to('admin/main_page_setting/short_about_us');
        }
    }

    function update_about_page_overview_hi()
    {
        $home = new MainpageModel();
        $upload = new UploadModel();
        $data['about_title'] = $this->request->getVar('about_title');
        $data['about_content'] = $this->request->getVar('about_content');
        if($home->update_about_page_overview($data, 2))
        {
            session()->set('success', "Section Successfully Updated");
            return redirect()->to('admin/main_page_setting/short_about_us');
        }
        else
        {
            session()->set('error', "Section Updated Failed");
            return redirect()->to('admin/main_page_setting/short_about_us');
        }
    }

    function shoart_about_us()
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['overview_en'] = $home->get_about_us_overview('en');
        $data['overview_hi'] = $home->get_about_us_overview('hi');
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/short_about_us');
        echo view('admin/include/footer');
    }

    function update_section_heading()
    {
        $home = new MainpageModel();
        $data['milestone_awards'] = $this->request->getVar('milestone_awards');
        $data['our_team'] = $this->request->getVar('our_team');
        $data['advisors'] = $this->request->getVar('advisors');
        $data['report'] = $this->request->getVar('report');
        $data['legal_document'] = $this->request->getVar('legal_document');
        if($home->update_section_heading($data))
        {
            session()->set('success', "Heading Successfully Updated");
            return redirect()->to('admin/main_page_setting/short_about_us');
        }
        else
        {
            session()->set('error', "Heading Updated Failed");
            return redirect()->to('admin/main_page_setting/short_about_us');
        }
    }

    function add_new_gallery_category()
    {
        $home = new MainpageModel();
        $data['gc_name'] = $this->request->getVar('gc_name');
        $data['gc_name_hindi'] = $this->request->getVar('gc_name_hindi');
        if($home->add_new_gallery_category($data))
        {
            session()->set('success', "Category Successfully Added");
            return redirect()->to('admin/main_page_setting/gallery');
        }
        else
        {
            session()->set('error', "Category Added Failed");
            return redirect()->to('admin/main_page_setting/gallery');
        }
    }

    function delete_gallery_category($id)
    {
        $home = new MainpageModel();
        if($home->delete_gallery_category($id))
        {
            session()->set('success', "Category Successfully Delete");
            return redirect()->to('admin/main_page_setting/gallery');
        }
        else
        {
            session()->set('error', "Category Delete Failed");
            return redirect()->to('admin/main_page_setting/gallery');
        }
    }

    function update_gallery_category($id)
    {
        $home = new MainpageModel();
        $data['gc_name'] = $this->request->getVar('gc_name');
        $data['gc_name_hindi'] = $this->request->getVar('gc_name_hindi');
        if($home->update_gallery_category($data, $id))
        {
            session()->set('success', "Category Successfully Added");
            return redirect()->to('admin/main_page_setting/gallery');
        }
        else
        {
            session()->set('error', "Category Added Failed");
            return redirect()->to('admin/main_page_setting/gallery');
        }
    }

    function media_corner()
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['all_media_category'] = $home->get_all_media_corner_category();
        $data['all_gallery'] = $home->get_all_media_corner_gallery();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/media_corner');
        echo view('admin/include/footer');
    }

    function add_new_media_category()
    {
        $home = new MainpageModel();
        $data['mcc_name'] = $this->request->getVar('mcc_name');
        if($home->add_new_media_category($data))
        {
            session()->set('success', "Category Successfully Added");
            return redirect()->to('admin/main_page_setting/media_corner');
        }
        else
        {
            session()->set('error', "Category Added Failed");
            return redirect()->to('admin/main_page_setting/media_corner');
        }
    }

    function delete_media_category($id)
    {
        $home = new MainpageModel();
        if($home->delete_media_category($id))
        {
            session()->set('success', "Category Successfully Delete");
            return redirect()->to('admin/main_page_setting/media_corner');
        }
        else
        {
            session()->set('error', "Category Delete Failed");
            return redirect()->to('admin/main_page_setting/media_corner');
        }
    }

    function update_media_category($id)
    {
        $home = new MainpageModel();
        $data['mcc_name'] = $this->request->getVar('mcc_name');
        if($home->update_media_category($data, $id))
        {
            session()->set('success', "Category Successfully Added");
            return redirect()->to('admin/main_page_setting/media_corner');
        }
        else
        {
            session()->set('error', "Category Added Failed");
            return redirect()->to('admin/main_page_setting/media_corner');
        }
    }

    function delete_media_corner($id)
    {
        $home = new MainpageModel();
        $slider_img = $home->get_media_corner_by_id($id);
        if (file_exists(substr($slider_img->media_image, 1))) {
                unlink(substr($slider_img->media_image, 1));
            }
        if($home->delete_media_corner($id))
        {
            session()->set('success', "Image Successfully Deleted");
            return redirect()->to('admin/main_page_setting/media_corner');
        }
        else
        {
            session()->set('error', "Image Deleted Failed");
            return redirect()->to('admin/main_page_setting/media_corner');
        }
    }

    function add_media_corner_item()
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['all_media_category'] = $home->get_all_media_corner_category();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/add_media_corner_item');
        echo view('admin/include/footer');
    }

    function add_new_media_corner_gallery()
    {
        $home = new MainpageModel();
        $upload = new UploadModel();
        $data['media_name'] = $this->request->getVar('media_name');
        $data['media_category'] = $this->request->getVar('media_category');
        if($this->request->getFile('media_image')->isValid() && !$this->request->getFile('media_image')->hasMoved())
        {
            $data['media_image'] = $upload->upload_image_2($this->request->getFile('media_image'));
        }

        if($home->add_new_media_corner_gallery($data))
        {
            session()->set('success', "Image Successfully Added");
            return redirect()->to('admin/main_page_setting/media_corner');
        }
        else
        {
            session()->set('error', "Image Updated Added");
            return redirect()->to('admin/main_page_setting/media_corner');
        }
    }

    public function add_new_brand()
    {
        $setting = new SettingModel();
        $data['app_setting'] = $setting->get_application_setting();
        echo view('admin/include/header', $data);
        echo view('admin/brand/add_new_brand');
        echo view('admin/include/footer');
    }

    function add_brand()
    {
        $brand = new MainpageModel();
        $upload = new UploadModel();
        if(!$brand->check_name_avaliblity($this->request->getVar('brand_name')))
        {
            $data['brand_name'] = $this->request->getVar('brand_name');
            $data['brand_slug'] = slug($this->request->getVar('brand_name'));

            if($this->request->getFile('brand_image')->isValid() && !$this->request->getFile('brand_image')->hasMoved())
            {
                $data['brand_image'] = $upload->upload_image($this->request->getFile('brand_image'));
            }
            if($brand->add_brand($data))
            {
                session()->set('success', "Brand Successfully Added");
                return redirect()->route('admin/main_page_setting/view_all_brand');
            }
            else
            {
                session()->set('error', "Brand Added Failed");
                return redirect()->route('admin/main_page_setting/view_all_brand');
            }
        }
        else
        {
            session()->set('error', "Brand Name Already Edits");
            return redirect()->route('admin/main_page_setting/view_all_brand');
        }
    }

    function view_all_brand()
    {
        $brand = new MainpageModel();
        $setting = new SettingModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['all_brand'] = $brand->get_all_brand();
        echo view('admin/include/header', $data);
        echo view('admin/brand/view_all_brand');
        echo view('admin/include/footer');
    }

    function delete_brand($id)
    {
        $brand = new MainpageModel();
        $image = $brand->get_brand_by_id($id);
        if(file_exists(substr($image->brand_image, 1)))
        {
            unlink(substr($image->brand_image, 1));
        }
        if($brand->delete_brand($id))
        {
            session()->set('success', "Brand Successfully Deleted");
            return redirect()->route('admin/main_page_setting/view_all_brand');
        }
        else
        {
            session()->set('error', "Brand Deleted Failed");
            return redirect()->route('admin/main_page_setting/view_all_brand');
        }
    }

    function edit_brand($id)
    {
        $brand = new MainpageModel();
        $setting = new SettingModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['brand'] = $brand->get_brand_by_id($id);
        echo view('admin/include/header', $data);
        echo view('admin/brand/edit_brand');
        echo view('admin/include/footer');
    }

    function update_brand($id)
    {
        $brand = new MainpageModel();
        $upload = new UploadModel();
        $data['brand_name'] = $this->request->getVar('brand_name');
        $data['brand_slug'] = slug($this->request->getVar('brand_name'));
       
        if($this->request->getFile('brand_image')->isValid() && !$this->request->getFile('brand_image')->hasMoved())
        {
            $image = $brand->get_brand_by_id($id);
            if(file_exists(substr($image->brand_image, 1)))
            {
                unlink(substr($image->brand_image, 1));
            }
            $data['brand_image'] = $upload->upload_image($this->request->getFile('brand_image'));
        }
        
        if($brand->update_brand($data, $id))
        {
            session()->set('success', "Brand Successfully Updated");
            return redirect()->route('admin/main_page_setting/view_all_brand');
        }
        else
        {
            session()->set('error', "Brand Updated Failed");
            return redirect()->route('admin/main_page_setting/view_all_brand');
        }
    }

    function all_pages()
    {
        $setting = new SettingModel();
        $home = new HomeModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['get_all_page'] = $home->get_all_page();
        echo view('admin/include/header', $data);
        echo view('admin/home_setting/page_setting');
        echo view('admin/include/footer');
    }

    function add_new_page()
    {
        $setting = new SettingModel();
        $data['app_setting'] = $setting->get_application_setting();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/add_new_page');
        echo view('admin/include/footer');
    }

    function new_page_add()
    {
        $home = new HomeModel();
        $upload = new UploadModel();
        $data['name'] = $this->request->getVar('name');
        $data['slug'] = slug($this->request->getVar('name'));
        $data['content'] = $this->request->getVar('content');
        $data['meta_descrition'] = $this->request->getVar('meta_descrition');
        $data['meta_keyword'] = $this->request->getVar('meta_keyword');
        $data['status'] = 1;
        $data['important'] = $this->request->getVar('important');
        
       
        if($this->request->getFile('image')->isValid() && !$this->request->getFile('image')->hasMoved())
        {
            $data['image'] = $upload->upload_image($this->request->getFile('image'));
        }
        if($home->add_new_page($data))
        {
            session()->set('success', "Page Successfully Added");
            return redirect()->to('admin/main_page_setting/all_pages');
        }
        else
        {
            session()->set('error', "Page Added Failed");
            return redirect()->to('admin/main_page_setting/all_pages');
        }
    }

    function edit_page($id)
    {
        $home = new HomeModel();
        $setting = new SettingModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['page'] = $home->get_page_by_id($id);
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/edit_page');
        echo view('admin/include/footer');
    }

    function update_page($id)
    {
        $home = new HomeModel();
        $upload = new UploadModel();
        $data['name'] = $this->request->getVar('name');
        $data['slug'] = slug($this->request->getVar('name'));
        $data['content'] = $this->request->getVar('content');
        $data['meta_descrition'] = $this->request->getVar('meta_descrition');
        $data['meta_keyword'] = $this->request->getVar('meta_keyword');
        // $data['status'] = $this->request->getVar('status');
        $data['important'] = $this->request->getVar('important');
        
        $page_img = $home->get_page_by_id($id);
        if($this->request->getFile('image')->isValid() && !$this->request->getFile('image')->hasMoved())
        {
            if (file_exists(substr($page_img->image, 1))) {
                unlink(substr($page_img->image, 1));
            }
            $data['image'] = $upload->upload_image($this->request->getFile('image'));
        }

        if($home->update_page($data, $id))
        {
            session()->set('success', "Page Successfully Updated");
            return redirect()->to('admin/main_page_setting/all_pages');
        }
        else
        {
            session()->set('error', "Page Updated Failed");
            return redirect()->to('admin/main_page_setting/all_pages');
        }
    }


    function delete_page($id)
    {
        $home = new HomeModel();
        if($home->delete_page($id))
        {
            session()->set('success', "Page Successfully Deleted");
            return redirect()->to('admin/main_page_setting/all_pages');
        }
        else
        {
            session()->set('error', "Page Deleted Failed");
            return redirect()->to('admin/main_page_setting/all_pages');
        }
    }

    function add_new_legal_document()
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/add_new_legal_document');
        echo view('admin/include/footer');
    }

    function new_legal_document_add()
    {
        $home = new MainpageModel();
        $upload = new UploadModel();
        $data['about_title'] = 'Legal Documents';
        $data['about_category'] = 'legal';
        $data['about_content'] = $this->request->getVar('about_content');
        if($this->request->getFile('about_image')->isValid() && !$this->request->getFile('about_image')->hasMoved())
        {
            $data['about_image'] = $upload->upload_image($this->request->getFile('about_image'));
        }

        if($home->new_legal_document_add($data))
        {
            session()->set('success', "Documents Successfully Added");
            return redirect()->to('admin/main_page_setting/short_about_us');
        }
        else
        {
            session()->set('error', "Documents Updated Added");
            return redirect()->to('admin/main_page_setting/short_about_us');
        }
    }

    function edit_legal_document($id)
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['legal'] = $home->get_legal_document_by_id($id);
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/edit_legal_document');
        echo view('admin/include/footer');
    }

    function update_legal_document($id)
    {
        $home = new MainpageModel();
        $upload = new UploadModel();
        $data['about_content'] = $this->request->getVar('about_content');
        $page_img = $home->get_legal_document_by_id($id);
        if($this->request->getFile('about_image')->isValid() && !$this->request->getFile('about_image')->hasMoved())
        {
            if (file_exists(substr($page_img->about_image, 1))) {
                unlink(substr($page_img->about_image, 1));
            }
            $data['about_image'] = $upload->upload_image($this->request->getFile('about_image'));
        }

        if($home->update_legal_document($data, $id))
        {
            session()->set('success', "Documents Successfully Updated");
            return redirect()->to('admin/main_page_setting/short_about_us');
        }
        else
        {
            session()->set('error', "Documents Updated Failed");
            return redirect()->to('admin/main_page_setting/short_about_us');
        }
    }

    function delete_legal_document($id)
    {
        $home = new MainpageModel();
        $slider_img = $home->get_legal_document_by_id($id);
        if (file_exists(substr($slider_img->about_image, 1))) {
                unlink(substr($slider_img->about_image, 1));
            }
        if($home->delete_legal_document($id))
        {
            session()->set('success', "Documents Successfully Deleted");
            return redirect()->to('admin/main_page_setting/short_about_us');
        }
        else
        {
            session()->set('error', "Documents Deleted Failed");
            return redirect()->to('admin/main_page_setting/short_about_us');
        }
    }

    public function menu_name_setting()
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['english_menu'] = $home->get_menu_name_setting_by_lan('en');
        $data['hindi_menu'] = $home->get_menu_name_setting_by_lan('hi');
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/menu_name_setting');
        echo view('admin/include/footer');
    }

    public function update_menu_name($lan)
    {
        $home = new MainpageModel();
        
        $data['menu_name_home'] = $this->request->getVar('menu_name_home');
        $data['menu_name_about_us'] = $this->request->getVar('menu_name_about_us');
        $data['menu_name_projects'] = $this->request->getVar('menu_name_projects');
        $data['menu_name_what_we_do'] = $this->request->getVar('menu_name_what_we_do');
        $data['menu_name_gallery'] = $this->request->getVar('menu_name_gallery');
        $data['menu_name_gallery_image'] = $this->request->getVar('menu_name_gallery_image');
        $data['menu_name_gallery_video'] = $this->request->getVar('menu_name_gallery_video');
        $data['menu_name_events'] = $this->request->getVar('menu_name_events');
        $data['menu_name_media_corner'] = $this->request->getVar('menu_name_media_corner');
        $data['menu_name_blog'] = $this->request->getVar('menu_name_blog');
        $data['menu_name_contact'] = $this->request->getVar('menu_name_contact');

        $data['member'] = $this->request->getVar('member');
        $data['our_core_team'] = $this->request->getVar('our_core_team');
        $data['our_founders'] = $this->request->getVar('our_founders');

        if($home->update_menu_name($data, $lan))
        {
            session()->set('success', "Menu Name Successfully Updated");
            return redirect()->to('admin/main_page_setting/menu_name_setting');
        }
        else
        {
            session()->set('error', "Menu Name Updated Failed");
            return redirect()->to('admin/main_page_setting/menu_name_setting');
        }
    }

    public function our_all_founders()
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['all_founder'] = $home->get_all_founder();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/all_founder');
        echo view('admin/include/footer');
    }

    public function add_new_founder()
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/add_new_founder');
        echo view('admin/include/footer');
    }

    public function add_founder()
    {
        $home = new MainpageModel();
        $upload = new UploadModel();

        $data['founder_name'] = $this->request->getVar('founder_name');
        $data['founder_designation'] = $this->request->getVar('founder_designation');
        $data['founder_description'] = $this->request->getVar('founder_description');
        $data['founder_language'] = $this->request->getVar('founder_language');

        if($this->request->getFile('founder_image')->isValid() && !$this->request->getFile('founder_image')->hasMoved())
        {
            $data['founder_image'] = $upload->upload_image($this->request->getFile('founder_image'));
        }

        if($home->add_founder($data))
        {
            session()->set('success', "Founder Successfully Added");
            return redirect()->to('admin/main_page_setting/our_all_founders');
        }
        else
        {
            session()->set('error', "Founder Added Failed");
            return redirect()->to('admin/main_page_setting/our_all_founders');
        }
    }

    public function edit_founder($id)
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['founder'] = $home->get_founder_by_id($id);
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/edit_founder');
        echo view('admin/include/footer');
    }

    public function update_founder($id)
    {
        $home = new MainpageModel();
        $upload = new UploadModel();

        $data['founder_name'] = $this->request->getVar('founder_name');
        $data['founder_designation'] = $this->request->getVar('founder_designation');
        $data['founder_description'] = $this->request->getVar('founder_description');
        $data['founder_language'] = $this->request->getVar('founder_language');

        $page_img = $home->get_founder_by_id($id);
        if($this->request->getFile('founder_image')->isValid() && !$this->request->getFile('founder_image')->hasMoved())
        {
            if (file_exists(substr($page_img->founder_image, 1))) {
                unlink(substr($page_img->founder_image, 1));
            }
            $data['founder_image'] = $upload->upload_image($this->request->getFile('founder_image'));
        }

        if($home->update_founder($data, $id))
        {
            session()->set('success', "Founder Successfully Updated");
            return redirect()->to('admin/main_page_setting/our_all_founders');
        }
        else
        {
            session()->set('error', "Founder Updated Added");
            return redirect()->to('admin/main_page_setting/our_all_founders');
        }
    }

    public function delete_founder($id)
    {
        $home = new MainpageModel();
        $slider_img = $home->get_founder_by_id($id);
        if (file_exists(substr($slider_img->founder_image, 1))) {
                unlink(substr($slider_img->founder_image, 1));
            }
        if($home->delete_founder($id))
        {
            session()->set('success', "Founder Successfully Deleted");
            return redirect()->to('admin/main_page_setting/our_all_founders');
        }
        else
        {
            session()->set('error', "Founder Deleted Failed");
            return redirect()->to('admin/main_page_setting/our_all_founders');
        }
    }

    /// Our Core Team 

    public function our_core_team()
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['all_founder'] = $home->get_all_core_team_for_admin();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/all_core_team');
        echo view('admin/include/footer');
    }

    public function add_new_core_team()
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/add_new_core_team');
        echo view('admin/include/footer');
    }

    public function add_core_team()
    {
        $home = new MainpageModel();
        $upload = new UploadModel();

        $data['founder_name'] = $this->request->getVar('founder_name');
        $data['founder_designation'] = $this->request->getVar('founder_designation');
        $data['founder_description'] = $this->request->getVar('founder_description');
        $data['founder_language'] = $this->request->getVar('founder_language');
        $data['founder_email'] = $this->request->getVar('founder_email');

        if($this->request->getFile('founder_image')->isValid() && !$this->request->getFile('founder_image')->hasMoved())
        {
            $data['founder_image'] = $upload->upload_image($this->request->getFile('founder_image'));
        }

        if($home->add_core_team($data))
        {
            session()->set('success', "Core Team Successfully Added");
            return redirect()->to('admin/main_page_setting/our_core_team');
        }
        else
        {
            session()->set('error', "Core Team Added Failed");
            return redirect()->to('admin/main_page_setting/our_core_team');
        }
    }

    public function edit_core_team($id)
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $data['app_setting'] = $setting->get_application_setting();
        $data['founder'] = $home->get_core_team_by_id($id);
        echo view('admin/include/header', $data);
        echo view('admin/main_setting/edit_core_team');
        echo view('admin/include/footer');
    }

    public function update_core_team($id)
    {
        $home = new MainpageModel();
        $upload = new UploadModel();

        $data['founder_name'] = $this->request->getVar('founder_name');
        $data['founder_designation'] = $this->request->getVar('founder_designation');
        $data['founder_description'] = $this->request->getVar('founder_description');
        $data['founder_language'] = $this->request->getVar('founder_language');
        $data['founder_email'] = $this->request->getVar('founder_email');

        $page_img = $home->get_core_team_by_id($id);
        if($this->request->getFile('founder_image')->isValid() && !$this->request->getFile('founder_image')->hasMoved())
        {
            if (file_exists(substr($page_img->founder_image, 1))) {
                unlink(substr($page_img->founder_image, 1));
            }
            $data['founder_image'] = $upload->upload_image($this->request->getFile('founder_image'));
        }

        if($home->update_core_team($data, $id))
        {
            session()->set('success', "Core Team Successfully Updated");
            return redirect()->to('admin/main_page_setting/our_core_team');
        }
        else
        {
            session()->set('error', "Core Team Updated Added");
            return redirect()->to('admin/main_page_setting/our_core_team');
        }
    }

    public function delete_core_team($id)
    {
        $home = new MainpageModel();
        $slider_img = $home->get_core_team_by_id($id);
        if (file_exists(substr($slider_img->founder_image, 1))) {
                unlink(substr($slider_img->founder_image, 1));
            }
        if($home->delete_core_team($id))
        {
            session()->set('success', "Core Team Successfully Deleted");
            return redirect()->to('admin/main_page_setting/our_core_team');
        }
        else
        {
            session()->set('error', "Core Team Deleted Failed");
            return redirect()->to('admin/main_page_setting/our_core_team');
        }
    }
    

    
}
