<?php

namespace App\Controllers;
use App\Controllers\BaseController;
use App\Models\SettingModel;
use App\Models\UserModel;
use App\Models\ProductModel;
use App\Models\HomeModel;
use App\Models\MainpageModel;
use App\Models\CategoryModel;
use App\Models\OrderModel;
use App\Models\BrandModel;
use App\Models\ContactModel;
use App\Models\UploadModel;
use App\Models\BlogModel;
use Razorpay\Api\Api;
use Razorpay\Api\Errors\SignatureVerificationError;
use App\Models\EmailModel;
use Dompdf\Dompdf; 
class Home extends BaseController
{

    function index()
    {
        if(isset($_GET['ref'])) 
        {
            $user = new UserModel();
            $ref_url = $_GET['ref'];
            if($u_details = $user->check_user_by_ref_link($ref_url))
            {
                session()->set('reff_link_id', $u_details->user_id);
            }
            return redirect()->route('join-us');
        }

        $setting    = new SettingModel();
        $home       = new MainpageModel();
        $blog       = new BlogModel();
        $user       = new UserModel();
        $data['validation']                  =  \Config\Services::validation();
        $data['app_setting']                = $setting->get_application_setting();
        $data['title']                      = $data['app_setting']->application_name;            
        $data['all_slider']                 = $home->get_all_slider_frontend(session()->get('lan'));
        $data['all_blog']                   = $blog->get_top_4_blog();
        $data['all_slider_stats']           = $home->get_all_slider_stats();
        $data['short_about_us']             = $home->get_shoart_about_us_content();
        $data['all_testimonials']           = $home->get_all_testimonials_for_home_page(session()->get('lan'));
        $data['all_slide_content']          = $home->get_all_slide_content();
        $data['counting_stats']             = $home->get_all_counting_stats();
        $data['all_latest_case']            = $home->get_all_latest_case_for_home_page();
        $data['all_event']                  = $home->get_all_event_for_home_page(session()->get('lan'));
        $data['all_gallery']                = $home->get_all_image_gallery_for_home_page();
        $data['all_gallery_category']       = $home->get_all_gallery_category();
        $data['all_featured_project']       = $home->get_all_featured_project_for_home_page(session()->get('lan'));
        $data['vol_data']                   = $home->get_all_became_a_volunteer(session()->get('lan'));
        $data['counting_stats']             = $home->get_all_counting_stats();
        $data['heading']                    = $home->get_heading_sub_heading();
        $data['all_brand']                  = $home->get_all_brand();
        $data['count_user']                 = $user->count_all_users_by_role('User');
        $data['all_founder']                = $home->get_all_founder_for_home_page(session()->get('lan'));
        $data['all_core_team']              = $home->get_all_core_team_for_home_page(session()->get('lan'));

        echo view('front/main_site/include/header', $data);
        echo view('front/main_site/home');
        echo view('front/main_site/include/footer');
        // echo '<pre>';
        // print_r($data['all_top_rated_prd']);
    }

    function about_us()
    {
        $setting    = new SettingModel();
        $home       = new MainpageModel();
        $blog       = new BlogModel();
        $data['app_setting']                = $setting->get_application_setting();
        $data['title']                      = 'About Us || '. $data['app_setting']->application_name;
        $data['overview']       = $home->get_about_us_overview(session()->get('lan'));
        
        // $data['heading']     = $home->get_heading_sub_heading();
        $data['page_title']          = $home->get_menu_name_setting_by_lan(session()->get('lan'));
        echo view('front/main_site/include/header', $data);
        echo view('front/main_site/about_us');
        echo view('front/main_site/include/footer');
    }

    
    function contact()
    {
        $setting = new SettingModel();
        $home       = new MainpageModel();
        
        $data['app_setting']            = $setting->get_application_setting();
        $data['title']                  = 'Contact || '.$data['app_setting']->application_name;
        $data['page_title']             = $home->get_menu_name_setting_by_lan(session()->get('lan'));
        echo view('front/main_site/include/header', $data);
        echo view('front/main_site/contact');
        echo view('front/main_site/include/footer');
    }

    function insert_contact_data()
    {
        $conatct = new ContactModel();
        $setting = new SettingModel();
        $input = $this->validate([
            'name' => 'required',
            'email' => 'required|valid_email',
            'phone' => 'required|numeric|max_length[10]',
            'subject' => 'required',
            'message' => 'required'
        ]);
        if (!$input) {
            $data = [
                'type' =>   'error',
                'msg'  =>   [
                    $this->validator->getError('name').'<br/>',
                    $this->validator->getError('email').'<br/>',
                    $this->validator->getError('phone').'<br/>',
                    $this->validator->getError('subject').'<br/>',
                    $this->validator->getError('message').'<br/>',
                ],
            ];
            echo json_encode($data);
        }
        else
        {
            $data = [
                'name' => $this->request->getVar('name'),
                'email' => $this->request->getVar('email'),
                'phone' => $this->request->getVar('phone'),
                'subject' => $this->request->getVar('subject'),
                'message' => $this->request->getVar('message'),
                'is_reply' => 0,
                'date_time' => date('Y-m-d h:i:s'),
            ];
            if($conatct->add_new_content_message($data))
            {
                $data = [
                    'type' =>   'success',
                    'msg'  =>   'Message Successfully Submitted. We will Contact You Shortly',
                ];
                echo json_encode($data);
            }
            else
            {
                $data = [
                    'type' =>   'error',
                    'msg'  =>   'Message Successfully Failed',
                ];
                echo json_encode($data);
            }
        }
            
        
    }

    function extra_page_details($slug)
    {
        $home = new HomeModel();
        $setting    = new SettingModel();
        $data['app_setting']                = $setting->get_application_setting();
        $data['page_details']               = $home->get_page_by_slug($slug);
        $data['title']                      = $data['page_details']->name.' || '.$data['app_setting']->application_name;
        $data['name'] = $data['page_details']->name;
        echo view('front/main_site/include/header', $data);
        echo view('front/main_site/extra_page_details');
        echo view('front/main_site/include/footer');
    }


    function check_mobile($mobile)
    {
        $user = new UserModel();
        $data = $user->check_user_avaliablity_by_details('user_mobile', $mobile);
        if($data)
        {
            $data = [
                'type' =>   'error',
            ];
            echo json_encode($data);
        }
        else
        {
            $data = [
                'type' =>   'success',
            ];
            echo json_encode($data);
        }
    }

    function check_email($email)
    {
        $user = new UserModel();
        $data = $user->check_user_avaliablity_by_details('user_email', $email);
        if($data)
        {
            $data = [
                'type' =>   'error',
            ];
            echo json_encode($data);
        }
        else
        {
            $data = [
                'type' =>   'success',
            ];
            echo json_encode($data);
        }
    }

    function close_top_header_banner()
    {
        helper("cookie");
        set_cookie("top_header_banner", "10", 3600000);  
    }

    function close_cookies_bar()
    {
        helper("cookie");
        set_cookie("cookies_bar", "10", 3600000);  
    }


    function all_blog()
    {
        $setting = new SettingModel();
        $blog = new BlogModel();
        $product = new ProductModel();
        $data['app_setting']            = $setting->get_application_setting();
        $data['title']                  = 'Blog || '.$data['app_setting']->application_name;
        $data['all_blog']               = $blog->get_all_blog_for_all_blog_page();
        $data['top_4_blog']             = $blog->get_top_4_blog();
        $data['all_category']           = $blog->get_all_category();
        echo view('front/include/header', $data);
        echo view('front/all_blog');
        echo view('front/include/footer');
    }

    function blog_details($slug)
    {
        $setting = new SettingModel();
        $blog = new BlogModel();
        $product = new ProductModel();
        $data['app_setting']            = $setting->get_application_setting();
        $data['blog']                   = $blog->get_blog_by_slug($slug);
        $data['title']                  = 'Blog || '.$data['app_setting']->application_name;
        $data['top_4_blog']             = $blog->get_top_4_blog();
        $data['all_category']           = $blog->get_all_category();
        echo view('front/include/header', $data);
        echo view('front/blog_details');
        echo view('front/include/footer');

        // echo '<pre>';
        // print_r($data['blog'] );
    }


    function case_details($slug)
    {
        $page = new MainpageModel();
        $info = $page->get_latest_case_by_slug($slug);
        if($info)
        {
            $setting = new SettingModel();
            
            $data['app_setting']            = $setting->get_application_setting();
            $data['title']                  = $info->latest_case_title.' || '.$data['app_setting']->application_name;
            $data['case']                   = $info;
            $data['all_latest_case']        = $page->get_all_latest_case_for_details_page($info->latest_case_id);
            $data['all_event']              = $page->get_all_event();
            echo view('front/main_site/include/header', $data);
            echo view('front/main_site/latest_case');
            echo view('front/main_site/include/footer');
        }
        else
        {
            return redirect()->route('/');
        }
    }

    function all_event()
    {
        $page = new MainpageModel();
        $setting = new SettingModel();
        $data['app_setting']            = $setting->get_application_setting();
        $data['title']                  = 'Event || '.$data['app_setting']->application_name;
        $data['all_event']              = $page->get_all_event_for_home_page(session()->get('lan'));
        $data['page_title']             = $page->get_menu_name_setting_by_lan(session()->get('lan'));
        echo view('front/main_site/include/header', $data);
        echo view('front/main_site/all_event');
        echo view('front/main_site/include/footer');
    }

    function event_details($slug)
    {
        $page = new MainpageModel();
        $info = $page->get_event_by_slug($slug);
        if($info)
        {
            $setting = new SettingModel();
            
            $data['app_setting']            = $setting->get_application_setting();
            $data['title']                  = $info->page_event_title.' || '.$data['app_setting']->application_name;
            $data['event']                  = $info;
            $data['all_event']              = $page->get_all_event();
            $data['all_latest_case']        = $page->get_all_latest_case_for_home_page();
            echo view('front/main_site/include/header', $data);
            echo view('front/main_site/event_details');
            echo view('front/main_site/include/footer');
        }
        else
        {
            return redirect()->route('/');
        }
    }   

    function join_us()
    {
        $setting = new SettingModel();
        $data['app_setting']            = $setting->get_application_setting();
        $data['validation']                  =  \Config\Services::validation();
        $data['title']                  = 'Join Us || '.$data['app_setting']->application_name;
        echo view('front/main_site/include/header', $data);
        echo view('front/main_site/join_us');
        echo view('front/main_site/include/footer');
    }

    function details_blog($slug)
    {
        $setting = new SettingModel();
        $blog = new BlogModel();
        $blog_data = $blog->get_blog_by_slug($slug);
        if($blog_data)
        {
            helper("cookie");
            $data['app_setting']            = $setting->get_application_setting();
            $data['blog']                   = $blog_data;
            $data['title']                  = $blog_data->title.' || '.$data['app_setting']->application_name;
            $data['top_4_blog']             = $blog->get_top_4_blog();
            $data['all_category']           = $blog->get_all_category();

            $get_cookie = get_cookie('blog_id_'.$data['blog']->id); 
            if($get_cookie != 'blog_id_'.$data['blog']->id)
            {
                
                $cookie = array(
                     'name'   => 'blog_id_'.$data['blog']->id,
                     'value'  => 'blog_id_'.$data['blog']->id,
                     'expire' => '86400',
                     'prefix' => ''
                  );
                set_cookie($cookie);
                $viewUpdate = array(
                    'view' => $data['blog']->view +1, 
                );
               $blog->update_blog_view($viewUpdate, $data['blog']->id);
            }
            echo view('front/main_site/include/header', $data);
            echo view('front/main_site/blog_details');
            echo view('front/main_site/include/footer');
        }
        else
        {
            return redirect()->route('/');
        }
    }

    function blog_category($slug)
    {
        $setting = new SettingModel();
        $blog = new BlogModel();
        $blog_data = $blog->get_all_blog_by_category_slug($slug);
        if($blog_data)
        {
            $data['app_setting']            = $setting->get_application_setting();
            $data['all_blog']               = $blog_data;
            $data['title']                  = $blog_data[0]->category_name.' || '.$data['app_setting']->application_name;
            $data['top_4_blog']             = $blog->get_top_4_blog();
            $data['all_category']           = $blog->get_all_category();
            echo view('front/main_site/include/header', $data);
            echo view('front/main_site/blog_category');
            echo view('front/main_site/include/footer');
        }
        else
        {
            return redirect()->route('/');
        }
        // echo '<pre>';
        // print_r($blog_data[0]->category_name);
    }



    function featured_project_details($slug)
    {
        $setting = new SettingModel();
        $home = new MainpageModel();
        $project_data = $home->get_featured_project_details_slug($slug);
        if($project_data)
        {
            $data['app_setting']            = $setting->get_application_setting();
            $data['project']                = $project_data;
            $data['title']                  = $project_data->project_title.' || '.$data['app_setting']->application_name;
            $data['all_featured_project']       = $home->get_all_featured_project_for_home_page(session()->get('lan'));
            echo view('front/main_site/include/header', $data);
            echo view('front/main_site/featured_project_details');
            echo view('front/main_site/include/footer');
        }
        else
        {
            return redirect()->route('/');
        }
    }

    function submit_donation()
    {
        $setting = new SettingModel();
        $recharge_id = rand();
        $amount = $this->request->getVar('d_amount');
        session()->set('rechage_id', $recharge_id);
        session()->set('donation_amount', $amount);
        session()->set('d_name', $this->request->getVar('d_name'));
        session()->set('d_email', $this->request->getVar('d_email'));
        session()->set('d_mobile', $this->request->getVar('d_mobile'));
        session()->set('project_id', $this->request->getVar('d_project_id'));
        session()->set('d_pin', $this->request->getVar('d_pin'));
        session()->set('d_address', $this->request->getVar('d_address'));
        session()->set('d_area', $this->request->getVar('d_area'));
        session()->set('d_dist', $this->request->getVar('d_dist'));
        session()->set('d_state', $this->request->getVar('d_state'));
        $app_setting = $setting->get_application_setting();
        $api = new Api($app_setting->rozar_key_id, $app_setting->rozar_key_secret);
        $_SESSION['payable_amount'] = $amount;
        $razorpayOrder = $api->order->create(array(
            'receipt'         => $recharge_id,
            'amount'          => $amount * 100, 
            'currency'        => 'INR',
            'payment_capture' => 1 
        ));
        $amount = $razorpayOrder['amount'];
        $razorpayOrderId = $razorpayOrder['id'];
        $_SESSION['razorpay_order_id'] = $razorpayOrderId;
        $_SESSION['recharge_id'] = $recharge_id;
        $_SESSION['amount'] = $amount;
        $raz_pay_data = $this->rozr_pay_prepareData_3($amount,$razorpayOrderId, $recharge_id);
        echo view('rezorpay_donation_payment', array('data' => $raz_pay_data));
        
    }

    public function rozr_pay_prepareData_3($amount,$razorpayOrderId, $order_id)
    {
        // $info = session()->get('user_login_details');
        $setting = new SettingModel();
        $app_setting = $setting->get_application_setting(); 
        $data = array(
            "key" => $app_setting->rozar_key_id,
            "amount" => $amount,
            "name" => $app_setting->application_name,
            "description" => 'Donation Payment',
            "image" => base_url().'/'.$app_setting->header_logo,
            "prefill" => array(
                "name"  => session()->get('d_name'),
                "email"  => session()->get('d_email'),
                "contact" => session()->get('d_mobile'),
            ),
            "notes"  => array(
                // "address"  => user()->user_address,
                "merchant_order_id" => rand(),
            ),
            "theme"  => array(
                "color"  => "#F37254"
            ),
            "order_id" => $razorpayOrderId,
        );
        return $data;
    }


    function rozr_pay_verify_donation()
    {
        $setting = new SettingModel();
        $app_setting = $setting->get_application_setting();
        $order_id = session()->get('rechage_id');
        $amount_recharge = $_SESSION['amount'] / 100;
        $success = true;
        $error = "payment_failed";
        if (empty($_POST['razorpay_payment_id']) === false) {
            $api = new Api($app_setting->rozar_key_id, $app_setting->rozar_key_secret);
        try {
                $attributes = array(
                    'razorpay_order_id' => $_SESSION['razorpay_order_id'],
                    'razorpay_payment_id' => $_POST['razorpay_payment_id'],
                    'razorpay_signature' => $_POST['razorpay_signature']
                );
                $api->utility->verifyPaymentSignature($attributes);
            } catch(SignatureVerificationError $e) {
                $success = false;
                $error = 'Razorpay_Error : ' . $e->getMessage();
            }
        }
        if ($success === true) 
        {
            $data['donation_name']          = session()->get('d_name');
            $data['donation_email']         = session()->get('d_email');
            $data['donation_mobile']        = session()->get('d_mobile');
            $data['donation_amount']        = session()->get('donation_amount');
            $data['donation_project_id']    = session()->get('project_id');
            $data['donation_pay_id']        = $_POST['razorpay_payment_id'];
            $data['donation_date']          = date('Y-m-d');
            $data['donation_pin_code']      =session()->get('d_pin');
            $data['donation_address']       =session()->get('d_address');
            $data['donation_area']          =session()->get('d_area');
            $data['donation_dist']          =session()->get('d_dist');
            $data['donation_state']         =session()->get('d_state');
            session()->set('donation_date', date('d-M-Y'));
            $setting->add_new_donation_amount($data);

            $email = new EmailModel();
            $home = new MainpageModel();
            $subject = 'Thank You For Your Donation';
            $email_data['title'] = 'Thank You For Your Donation';
            $email_data['name'] = session()->get('d_name');
            $email_data['app_setting'] = $setting->get_application_setting();
            $email_data['project']     = $home->get_all_featured_project_by_id(session()->get('project_id'));
            $msg = view('email/donation_email', $email_data);
            $email_id = session()->get('d_email');
            $email->send_email($email_id, $subject, $msg, $mailType = 'html', $subject);

            session()->set('pay_success', true);
            return redirect()->route('payment-success');
            
        }
        else 
        {
            $this->session->set_userdata('error', 'Transaction Faild');
            return redirect()->route('/');
        }
    }

    function payment_success()
    {
        if(session()->get('pay_success'))
        {
            $setting    = new SettingModel();
            $data['app_setting']        = $setting->get_application_setting();
            $data['title']              = 'Payment Success || '. $data['app_setting']->application_name;
            echo view('front/main_site/include/header', $data);
            echo view('front/main_site/pay_success');
            echo view('front/main_site/include/footer');
        }
        else
        {
            return redirect()->route('/');
        }
    }

    function download_receipt()
    {
        if(session()->get('pay_success'))
        {
            $home = new MainpageModel();
            $data['project']            = $home->get_all_featured_project_by_id(session()->get('project_id'));
            $data['image_d'] = $this->file_get_contents_curl(base_url().'/donation_r.jpg');
            echo view('front/main_site/download_receipt', $data);
        }
        else
        {
            return redirect()->route('/');
        }
    }

    function file_get_contents_curl($url) {
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);       

        $data = curl_exec($ch);
        curl_close($ch);

        return $data;
    }

    function submit_join_us_form()
    {
        $user = new UserModel();
        $email = new EmailModel();
        $setting = new SettingModel();

        $check_email = $user->get_user_by_details('user_email', $this->request->getVar('user_email'));
        if($check_email)
        {
            session()->set('error', "Email ID Already Exits");
            return redirect()->route('/');
        }
        $user_mobile = $user->get_user_by_details('user_mobile', $this->request->getVar('user_mobile'));
        if($user_mobile)
        {
            session()->set('error', "Phone No Already Exits");
            return redirect()->route('/');
        }
        $data['user_name'] = $this->request->getVar('user_name');
        $data['user_mobile'] = $this->request->getVar('user_mobile');
        $data['user_email'] = $this->request->getVar('user_email');
        $data['user_address'] = $this->request->getVar('user_address');
        $data['user_role'] = 'Volunteer';
        $data['user_status'] = 'Active';
        $data['user_password'] = hash("sha256", rand());
        $data['created_at'] = date('Y-m-d');
        $data['user_stock_point_code'] = $user->get_vol_last_code();
        session()->set('vol_name', $this->request->getVar('user_name'));
        session()->set('vol_date', date('Y-m-d'));
        session()->set('member_id', $data['user_stock_point_code']);
        if($user->submit_join_us_form($data))
        {
            $subject = 'Thank You For Joining';
            $email_data['title'] = 'Thank You For Joining';
            $email_data['name'] = $this->request->getVar('user_name');
            $email_data['app_setting'] = $setting->get_application_setting();
            $msg = view('email/member_reg_email', $email_data);
            $email_id = $this->request->getVar('user_email');
            $email->send_email($email_id, $subject, $msg, $mailType = 'html', $subject);
                    
             session()->set('success', "Thank You For Joining. We will Contact You Shortly");
             return redirect()->route('joining');
         }
        else
        {
             session()->set('error', "Joining Failed");
             return redirect()->route('/');
        }
    }

    function joining()
    {
        if(session()->get('vol_name'))
        {
            $setting    = new SettingModel();
            $data['app_setting']        = $setting->get_application_setting();
            $data['title']              = 'Joining || '. $data['app_setting']->application_name;
            echo view('front/main_site/include/header', $data);
            echo view('front/main_site/joining');
            echo view('front/main_site/include/footer');
        }
        else
        {
            return redirect()->route('/');
        }
    }

    function download_membership_certificate()
    {
        if(session()->get('vol_name'))
        {
            $data['image_d'] = $this->file_get_contents_curl(base_url().'/member_c.jpg');
            echo view('front/main_site/download_member_certificate', $data);
        }
        else
        {
            return redirect()->route('/');
        }
    }

    function all_img_gallery()
    {
        $setting    = new SettingModel();
        $home       = new MainpageModel();
        $data['app_setting']                = $setting->get_application_setting();
        $data['title']                      = 'Image Gallery || '. $data['app_setting']->application_name;
        $data['all_gallery'] = $home->get_all_gallery();
        $data['all_category'] = $home->get_all_gallery_category();
        $data['page_title']          = $home->get_menu_name_setting_by_lan(session()->get('lan'));
        echo view('front/main_site/include/header', $data);
        echo view('front/main_site/all_img_gallery');
        echo view('front/main_site/include/footer');
    }

    function all_img_video()
    {
        $setting    = new SettingModel();
        $home       = new MainpageModel();
        $data['app_setting']                = $setting->get_application_setting();
        $data['title']                      = 'Video Gallery || '. $data['app_setting']->application_name;
        $data['all_gallery'] = $home->get_all_gallery();
        $data['all_category'] = $home->get_all_gallery_category();
        $data['page_title']          = $home->get_menu_name_setting_by_lan(session()->get('lan'));
        echo view('front/main_site/include/header', $data);
        echo view('front/main_site/all_img_video');
        echo view('front/main_site/include/footer');
    }

    function donate_now()
    {
        $setting    = new SettingModel();
        $home       = new MainpageModel();
        $data['app_setting']                = $setting->get_application_setting();
        $data['title']                      = 'Donate Now || '. $data['app_setting']->application_name;
        $data['all_project']                =  $home->get_all_featured_project_for_donate_page(session()->get('lan'));
        $data['all_testimonials']           = $home->get_all_testimonials();
        echo view('front/main_site/include/header', $data);
        echo view('front/main_site/donate_now');
        echo view('front/main_site/include/footer');
    }

    function media_corner()
    {
        $setting    = new SettingModel();
        $home       = new MainpageModel();
        $data['app_setting']                = $setting->get_application_setting();
        $data['title']                      = 'Media Corner || '. $data['app_setting']->application_name;
        $data['all_media_category']         = $home->get_all_media_corner_category();
        $data['all_gallery']                = $home->get_all_media_corner_gallery();
        $data['page_title']                 = $home->get_menu_name_setting_by_lan(session()->get('lan'));
        echo view('front/main_site/include/header', $data);
        echo view('front/main_site/media_corner');
        echo view('front/main_site/include/footer');
    }

    function all_projects()
    {
        $setting    = new SettingModel();
        $home       = new MainpageModel();
        $data['app_setting']                = $setting->get_application_setting();
        $data['title']                      = 'Projects || '. $data['app_setting']->application_name;
        $data['all_featured_project']       = $home->get_all_featured_project_for_home_page(session()->get('lan'));
        $data['page_title']          = $home->get_menu_name_setting_by_lan(session()->get('lan'));
        echo view('front/main_site/include/header', $data);
        echo view('front/main_site/all_projects');
        echo view('front/main_site/include/footer');
    }

    function what_we_do()
    {
        $setting    = new SettingModel();
        $home       = new MainpageModel();
        $data['app_setting']                = $setting->get_application_setting();
        $data['title']                      = 'What We Do || '. $data['app_setting']->application_name;
        $data['all_latest_case']            = $home->get_all_latest_case_for_home_page();
        $data['page_title']          = $home->get_menu_name_setting_by_lan(session()->get('lan'));
        echo view('front/main_site/include/header', $data);
        echo view('front/main_site/all_case');
        echo view('front/main_site/include/footer');
    }

    function subscriber()
    {
        $setting    = new SettingModel();
        $check_email = $setting->add_subscriber_by_email_id($this->request->getVar('subscribers_email'));
        if($check_email)
        {
            session()->set('error', "Email ID Already Exits");
            return redirect()->route('/');
        }
        else
        {
            $data['user_email']     = $this->request->getVar('subscribers_email');
            $data['user_role']      = 'Subscriber';    
            $data['created_at']     = date('Y-m-d');    
            if($setting->add_subscriber($data))
            {
                session()->set('success', "You Are Now Our Subscriber");
                return redirect()->route('/');
            }
            else
            {
                session()->set('error', "Subscription Failed");
                return redirect()->route('/');
            }
        }
    }

    function save_reaction()
    {
        $blog = new BlogModel();
        $post_id = $this->request->getVar('post_id');
        $reaction = $this->request->getVar('reaction');

        $post = $blog->get_blog_by_id($post_id);

        if (!empty($post)) 
        {
            $blog->save_reaction($post_id, $reaction);
        }
        $blog = $blog->get_blog_by_id_for_like_system($post_id);
        $data['blog'] =[
            'blog_id'   => $blog->id,
            'like'      => $blog->like,
            'dislike'   => $blog->dislike,
            'love'      => $blog->love
        ];
        echo view('front/main_site/reaction', $data);
    }

    public function get_aadress_detaile_by_pin_code($id)
    {
        if($id)
        {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL,'https://api.postalpincode.in/pincode/'.$id);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $response = curl_exec($ch);
            $result = json_decode($response);
            curl_close($ch);

            $area= '';
            foreach ($result[0]->PostOffice as $key => $value)
            {
                 $area .= '<option value="'.$value->Name.'">'.$value->Name.'</option>'; 
            } 
            $output = [
                'city' => $result[0]->PostOffice[0]->District,
                'state' => $state = $result[0]->PostOffice[0]->State,
                'area' => $area,
            ];
        }
        echo json_encode($output);
    }

    public function change_language()
    {
        session()->set('lan', $this->request->getVar('e'));
    }

    public function our_core_team()
    {
        $setting    = new SettingModel();
        $home       = new MainpageModel();
        $data['app_setting']                = $setting->get_application_setting();
        $data['title']                      = 'Our Core Team || '. $data['app_setting']->application_name;
        $data['all_core_team']              = $home->get_all_core_team(session()->get('lan'));
        $data['page_title']                 = $home->get_menu_name_setting_by_lan(session()->get('lan'));
        echo view('front/main_site/include/header', $data);
        echo view('front/main_site/our_core_team');
        echo view('front/main_site/include/footer');
    }

    public function our_founders()
    {
        $setting    = new SettingModel();
        $home       = new MainpageModel();
        $data['app_setting']                = $setting->get_application_setting();
        $data['title']                      = 'Our Founders || '. $data['app_setting']->application_name;
        $data['all_core_team']              = $home->get_all_founder_for_home_page(session()->get('lan'));
        $data['page_title']                 = $home->get_menu_name_setting_by_lan(session()->get('lan'));
        echo view('front/main_site/include/header', $data);
        echo view('front/main_site/our_founders');
        echo view('front/main_site/include/footer');
    }

    public function submit_donation_2()
    {
        $setting    = new SettingModel();
        if($this->request->getVar('extra_amount'))
        {
            $amount = $this->request->getVar('extra_amount');
        }
        else
        {
            $amount = $this->request->getVar('d_amount');
        }
        $data['donation_name']              = $this->request->getVar('d_name');
        $data['donation_name_in_acc']       = $this->request->getVar('d_acc_name');
        $data['donation_email']             = $this->request->getVar('d_email');
        $data['donation_mobile']            = $this->request->getVar('d_mobile');
        $data['donation_amount']            = $amount;
        $data['donation_project_id']        = $this->request->getVar('d_project_id');
        $data['donation_pay_id']            = $this->request->getVar('d_trans_id');
        $data['donation_date']              = date('Y-m-d');
        $data['donation_pin']               = $this->request->getVar('d_pin');
        $data['donation_address']           = $this->request->getVar('d_address');
        $data['donation_area']              = $this->request->getVar('d_area');
        $data['donation_dist']              = $this->request->getVar('d_dist');
        $data['donation_state']             = $this->request->getVar('d_state');
        $data['donation_payment_date_time'] = $this->request->getVar('d_trans_date');
        $data['donation_payment_type']      = $this->request->getVar('d_payment_type');
        $data['d_eight_g_form']             = $this->request->getVar('d_eight_g_form') == 1 ? 1 : 0;
        $data['d_pan_card']                 = $this->request->getVar('d_pan_card');

        if($setting->add_new_donation_amount($data))
        {
            session()->set('success', "Payment Data Successfully Save, Please Wait For Payment Approval");
            return redirect()->back();
        }
        else
        {
            session()->set('error', "Payment Data Save Failed");
            return redirect()->back();
        }
    }

}
