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੐)|#o0aڱ$I>}k&1`U#V?YsV x>{t1[I~D&(I$I/{H0fw"q"y%4 IXyE~M3 8XψL}qE$I[> nD?~sf ]o΁ cT6"?'_Ἣ $I>~.f|'!N?⟩0G KkXZE]ޡ;/&?k OۘH$IRۀwXӨ<7@PnS04aӶp.:@\IWQJ6sS%I$e5ڑv`3:x';wq_vpgHyXZ 3gЂ7{{EuԹn±}$I$8t;b|591nءQ"P6O5i }iR̈́%Q̄p!I䮢]O{H$IRϻ9s֧ a=`- aB\X0"+5"C1Hb?߮3x3&gşggl_hZ^,`5?ߎvĸ%̀M!OZC2#0x LJ0 Gw$I$I}<{Eb+y;iI,`ܚF:5ܛA8-O-|8K7s|#Z8a&><a&/VtbtLʌI$I$I$I$I$I$IRjDD%tEXtdate:create2022-05-31T04:40:26+00:00!Î%tEXtdate:modify2022-05-31T04:40:26+00:00|{2IENDB`Mini Shell

HOME


Mini Shell 1.0
DIR:/home/htlwork.com/www/edusort/app/Http/Controllers/Frontend/
Upload File :
Current File : /home/htlwork.com/www/edusort/app/Http/Controllers/Frontend/FormController.php
<?php

namespace App\Http\Controllers\Frontend;

use Illuminate\Http\Request;
use App\Models\User;
use Illuminate\Support\Facades\Mail;
use App\Mail\OtpMail;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator; 
use Illuminate\Support\Facades\Auth;   
use App\Models\Applications;
use Illuminate\Support\Facades\DB;
use App\Models\Qualification;
use App\Models\Wishlist;
use App\Models\CourseApplication;

use App\Mail\OfferLetter;

use App\Models\Offer_letter;
use App\Models\Cron_responce;
use Illuminate\Support\Str;


use App\Http\Controllers\Controller;
class FormController extends Controller
{
    public function createForm()
    {

        if(isset($_GET['course_id'])){
            $course_id=$_GET['course_id'];
        }else{
            $course_id=23;
        }
        $courses = DB::table('courses')
    ->select('*')
    ->where('id', $course_id)
    ->first();


   
        return view('frontend/user/form', compact('courses'));
    }

    public function processForm(Request $request)
    {
        $rules = [
            // 'title' => 'required|',
            //Personal Details 
            'family_name' => 'required|',
            'given_names' => 'required|',
            'former_family_name' => 'required|',
            'preferred_name' => 'required|',
            'date_of_birth' => 'required|',
            'passport_number' => 'required|',
            'country_of_birth' => 'required|',
            'nationality' => 'required|',
            'marital_status' => 'required|',
            'in_australia' => 'required|',



            //home address

            'home_address' => 'required|',
            'suburb_town' => 'required|',
            'state_region' => 'required|',
            'postcode_zip' => 'required|',
            'country' => 'required|',


            // Postal Address
            'postal_address' => 'required|',
            'postal_suburb_town' => 'required|',
            'postal_state_region' => 'required|',
            'postal_postcode_zip' => 'required|',
            'postal_country25' => 'required|',


           
            //Contact Details
            'email_address' => 'required|email|max:255',
            'telephone' => 'required|string|max:20',

            //Current Studys
            'currently_studying_australia' => 'required|',


            //Emergency Contact Details
            'emergency_contact_name' => 'required|',
            'emergency_contact_telephone' => 'required|string|max:20',
            'emergency_contact_email' => 'required|email|max:255',
          

          //English Language Proficiency
    'academic_english_course' => 'required',
    // 'english_tests' => 'required|array|min:1',
    // 'english_tests.*' => 'required|string|in:IELTS,TOEFL,PTE,Other',
    'english_tests' => 'required|string|in:IELTS,TOEFL,PTE,Other',

    'overall_band_score' => 'required|numeric|min:0|max:9',
    'listening' => 'required|numeric|min:0|max:9',
    'reading' => 'required|numeric|min:0|max:9',
    'writing' => 'required|numeric|min:0|max:9',
    'speaking' => 'required|numeric|min:0|max:9',

    
//Secondary Studies (Senior School)

'institution' => 'required|string',
'qualification' => 'required|string',
'course_length' => 'required|string',
'year_completion' => 'required|string',
'country11' => 'required|string',

  
//Post Secondary Studies

'institution1' => 'required|string',
'qualification1' => 'required|string',
'course_length1' => 'required|string',
'year_completion1' => 'required|string',
'country1' => 'required|string',
'institution2' => 'required|string',
'qualification2' => 'required|string',
'course_length2' => 'required|string',
'year_completion2' => 'required|string',
'country2' => 'required|string',
'advanced_standing' => 'required|string',


    
//Visa Information
'australian_visa_rejected' => 'required',
'other_country_visa_rejected' => 'required',
'current_australian_visa' => 'required',
'visa_subclass' => 'required',
'applying_student_visa' => 'required',
  
//Overseas Student Health Cover (OSHC)
'current_oshc' => 'required',
'oshc_cover_type' => 'required',


//Dependents Information
'bring_spouse' => 'required',
'bring_children' => 'required',
'number_of_children' => 'required_if:bring_children,Yes|nullable|integer|min:0',
    

//Declaration
'applicant_declaration' => 'accepted',

//Disability Support
'disability' => 'required',


//course apply for
// 'course_name' => 'required',







    
            
        ];
        $validator = Validator::make($request->all(), $rules);
        /* If validation fails */
        if ($validator->fails()) {
            return redirect()->back()
                            ->withErrors($validator)
                            ->withInput(); // To repopulate the form fields with the old input
        }



        $college = Applications::where('user_id', $request->login_user_id)->first();

if(!$college){

    $college = new Applications;
}














        
        
       $college->title = 'mr';
        //Personal Details 
        $college->family_name = $request->family_name;
        $college->given_names = $request->given_names;
        $college->former_family_name = $request->former_family_name;
        $college->preferred_name = $request->preferred_name;
        $college->date_of_birth = $request->date_of_birth;
        $college->passport_number = $request->passport_number;
        $college->country_of_birth = $request->country_of_birth;
        $college->nationality = $request->nationality;
        $college->marital_status = $request->marital_status;
        // $college->in_australia = $request->in_australia;
        $college->in_australia = $request->in_australia == '1' ? 1 : 0;
        //Home Address
        $college->home_address = $request->home_address;
        $college->suburb_town = $request->suburb_town;
        $college->state_region = $request->state_region;
        $college->postcode_zip = $request->postcode_zip;
        $college->country = $request->country;
        //Postal Address
        $college->postal_address = $request->postal_address;
        $college->postal_suburb_town = $request->postal_suburb_town;
        $college->postal_state_region = $request->postal_state_region;
        $college->postal_postcode_zip = $request->postal_postcode_zip;
        $college->postal_country25 = $request->postal_country25;
        //Contact Details
        $college->email_address = $request->email_address;
        $college->telephone = $request->telephone;
        //Emergency Contact Details
        $college->emergency_contact_name = $request->emergency_contact_name;
        $college->emergency_contact_telephone = $request->emergency_contact_telephone;
        $college->emergency_contact_email = $request->emergency_contact_email;

        //Current Study
        $college->currently_studying_australia = $request->currently_studying_australia;

        //

        //

        //

        //English Language Proficiency
$college->academic_english_course = $request->academic_english_course;
// Convert array of English tests to a comma-separated string
$englishTests = $request->english_tests;

// Assign the comma-separated string to the corresponding field in your model
$college->english_tests = $englishTests;
$college->overall_band_score = $request->overall_band_score;
$college->listening = $request->listening;
$college->reading = $request->reading;
$college->writing = $request->writing;
$college->speaking = $request->speaking;

//Secondary Studies (Senior School)
$college->institution = $request->institution;
$college->qualification = $request->qualification;
$college->course_length = $request->course_length;
$college->year_completion = $request->year_completion;
$college->country11 = $request->country11;

//Post Secondary Studies
$college->institution1 = $request->institution1;
$college->qualification1 = $request->qualification1;
$college->course_length1 = $request->course_length1;
$college->year_completion1 = $request->year_completion1;
$college->country1 = $request->country1;
$college->institution2 = $request->institution2;
$college->qualification2 = $request->qualification2;
$college->course_length2 = $request->course_length2;
$college->year_completion2 = $request->year_completion2;
$college->country2 = $request->country2;
$college->advanced_standing = $request->advanced_standing;

//Visa Information
$college->australian_visa_rejected = $request->australian_visa_rejected;
$college->other_country_visa_rejected = $request->other_country_visa_rejected;
//$college->current_australian_visa = $request->current_australian_visa;
$college->current_australian_visa = $request->current_australian_visa == '1' ? 'Yes' : 'No';

$college->visa_subclass = $request->visa_subclass;
//$college->applying_student_visa = $request->applying_student_visa;
$college->current_oshc = $request->current_oshc == '1' ? 'Yes' : 'No';


//Overseas Student Health Cover (OSHC)
//$college->current_oshc = $request->current_oshc;
$college->current_oshc = $request->current_oshc == '1' ? 'Yes' : 'No';

$college->oshc_cover_type = $request->oshc_cover_type;

//Dependents Information
// $college->bring_spouse = $request->bring_spouse;
$college->bring_spouse = $request->bring_spouse == '1' ? 'Yes' : 'No';

// $college->bring_children = $request->bring_children;

$college->bring_children = $request->bring_children == '1' ? 'Yes' : 'No';

$college->number_of_children = $request->number_of_children;
//Disability Support
// $college->disability = $request->disability;
$college->disability = $request->disability == '1' ? 'Yes' : 'No';

//$disability = $request->input('disability') == '1' ? 'YES' : 'NO';
$college->course_id = 'test';

//Declaration

$college->applicant_declaration = $request->has('applicant_declaration') ? 1 : 0;



// $college->applicant_signature = 'test';
// $college->applicant_date = 'test';


        // Handle image uploads

        if($college->save()){


 if($request->package_id !=''){

            $count_application = CourseApplication::where('user_id', $request->login_user_id)->get();


            if($count_application){
    
    
                if(count($count_application) >= 8){
                  
                    return redirect()->back()->withErrors(['You have reached maximum limit for apply']);
                }
    
            }

            $CourseApplication = CourseApplication::where('user_id', $request->login_user_id)->where('course_id', $request->package_id)->first();
            if($CourseApplication){
                return redirect()->back()->withErrors(['course already applied']);
               
            }
           
                   else{


            $CourseApplication = new CourseApplication();
            $CourseApplication->user_id = $request->login_user_id;
            $CourseApplication->course_id = $request->package_id;
            // Add other properties if needed
            if($CourseApplication->save()){





        
            return redirect()->back()->with('success', 'application form added successfully');


            }

            else{

                return redirect()->back()->withErrors(['Something went wrong. Please try again']);
            }


        }

    }

    else{
        return redirect()->back()->with('success', 'application form added successfully');
    }




        }
        
    
        // If the data saving is unsuccessful
      return redirect()->back()->withErrors(['Something went wrong. Please try again']);
    }








    public function update_user(Request $req){
        if($req->key2 ==''){
            return['message'=>''.$req->key1.' can not be empty','field_name'=>$req->key1,'status'=>500];
        }

        else{

            $user = User::where('id', $req->id)->first();
            
            if ($user) {
              $image='';


              if($req->key1 == 'emgphone' || $req->key1 == 'phone'){
                if(strlen($req->key2) < 10){
                    return['message'=>'phone number must be greater or equal to 10 digit','field_name'=>$req->key1,'status'=>500];
                }
              }


              if ($req->key1 == 'email') {
                // Validate email address format using filter_var
                if (!filter_var($req->key2, FILTER_VALIDATE_EMAIL)) {
                    return ['message' => 'Invalid email address format', 'field_name' => $req->key1, 'status' => 500];
                }
            } 



            if ($req->key1 == 'email') {
                

                $user_exist = User::where('email', $req->key2)
                ->where('id', '!=', $req->id)
                ->first();
                if ($user_exist) {
                    return ['message' => 'Email already exist', 'field_name' => $req->key1, 'status' => 500];
                }
            } 


           
            if($req->photo){
			$image = time().'.'.$req->photo->extension();
			$req->photo->move(public_path('frontend/images'), $image);
			
		}




                // Get the column name dynamically based on key1 value
                $column_name = $req->key1;
                
                // Update the user record with the provided key2 value and dynamic column name
              
                if($image != ''){
                $user->$column_name = $image;
                }
                else{
                    $user->$column_name = $req->key2;
                }
                $user->save();
                
                return ['message' => 'User updated successfully', 'status' => 200,'field_name'=>$req->key1];
            }

            else{
                return ['message' => 'Unauthorized user', 'status' => 404,'field_name'=>$req->key1];
            }
        }
      
    }




    public function update_document(Request $req){
        if($req->key2 ==''){
            return['message'=>''.$req->key1.' can not be empty','field_name'=>$req->key1,'status'=>500];
        }

        else{

            $user = User::where('id', $req->id)->first();
            
            if ($user) {
              $image='';

              if ($req->file->getClientOriginalExtension() !== 'pdf') {
                return ['message' => 'File must be a PDF', 'status' => 500, 'field_name' => $req->key1];
            }
            
            // Check file size
            if ($req->file->getSize() > 1024 * 1024) {
                return ['message' => 'File size must be less than 1 MB', 'status' => 500, 'field_name' => $req->key1];
            }



            if($req->file){
			$image = time().'.'.$req->file->extension();
			$req->file->move(public_path('assets/frontend/file/'), $image);
			
		}




                // Get the column name dynamically based on key1 value
                $column_name = $req->key1;
                
                // Update the user record with the provided key2 value and dynamic column name
              
                if($image != ''){
                $user->$column_name = $image;
                }
                
                if($user->save()){
                
                return ['message' => 'Document updated successfully', 'status' => 200,'field_name'=>$req->key1];
                }
                else{
                    return ['message' => 'something went wrong', 'status' => 500,'field_name'=>$req->key1];
            }
                
            }

            else{
                return ['message' => 'Unauthorized user', 'status' => 404,'field_name'=>$req->key1];
            }
        }
      
    }



    
    public function update_profile_pic(Request $req){
        if($req->key2 ==''){
            return['message'=>''.$req->key1.' can not be empty','field_name'=>$req->key1,'status'=>500];
        }

        else{

            $user = User::where('id', $req->id)->first();
            
            if ($user) {
              $image='';
              $allowedExtensions = ['jpg', 'jpeg', 'png', 'gif'];
              if (!in_array(strtolower($req->file('file')->getClientOriginalExtension()), $allowedExtensions)) {
                return ['message' => 'File must be an image (JPG, JPEG, PNG, GIF)', 'status' => 500, 'field_name' => $req->key1];
            }
            
            // Check file size
            if ($req->file->getSize() > 1024 * 1024) {
                return ['message' => 'File size must be less than 1 MB', 'status' => 500, 'field_name' => $req->key1];
            }



            if($req->file){
			$image = time().'.'.$req->file->extension();
			$req->file->move(public_path('assets/frontend/images/user/'), $image);
			
		}




                // Get the column name dynamically based on key1 value
                $column_name = $req->key1;
                
                // Update the user record with the provided key2 value and dynamic column name
              
                if($image != ''){
                $user->$column_name = $image;
                }
                
                if($user->save()){
                
                return ['message' => 'Document updated successfully', 'status' => 200,'field_name'=>$req->key1];
                }
                else{
                    return ['message' => 'something went wrong', 'status' => 500,'field_name'=>$req->key1];
            }
                
            }

            else{
                return ['message' => 'Unauthorized user', 'status' => 404,'field_name'=>$req->key1];
            }
        }
      
    }











    public function update_qualification(Request $req){

        





        if($req->key2 =='' && $req->qual_id == 0){
            return['message'=>'file can not be empty','status'=>500];
        }

       if($req->key3 ==''){
            return['message'=>'title can not be empty','status'=>500];
        }

        else{





            if($req->qual_id == 0){




            $user = new Qualification();
            
            if ($user) {
              $image='';

              if ($req->file->getClientOriginalExtension() !== 'pdf') {
                return ['message' => 'File must be a PDF', 'status' => 500,];
            }
            
            // Check file size
            if ($req->file->getSize() > 1024 * 1024) {
                return ['message' => 'File size must be less than 1 MB', 'status' => 500];
            }



            if($req->file){
			$image = time().'.'.$req->file->extension();
			$req->file->move(public_path('assets/frontend/file/'), $image);
			
		}
         if($image != ''){
                    $user->qualification_title = $req->key3;
                $user->file_name = $image;
                $user->user_id = $req-> id;
                $user->type=  $req-> type;
                }


            }

        }


else{


    $user = Qualification::where('id', $req->qual_id)->first();
            
    if ($user) {



if($req->key2 != ''){
        $image='';

        if ($req->file->getClientOriginalExtension() !== 'pdf') {
          return ['message' => 'File must be a PDF', 'status' => 500,];
      }
      
      // Check file size
      if ($req->file->getSize() > 1024 * 1024) {
          return ['message' => 'File size must be less than 1 MB', 'status' => 500];
      }



      if($req->file){
      $image = time().'.'.$req->file->extension();
      $req->file->move(public_path('assets/frontend/file/'), $image);
      
  }


}


   if($req->key2 != ''){
              $user->qualification_title = $req->key3;
          $user->file_name = $image;
        
          }else{
            $user->qualification_title = $req->key3;


          }





















    }else{

        return ['message' => 'something went wrong', 'status' => 500];


    }


}









                
                if($user->save()){
                
                return ['message' => 'Document updated successfully', 'status' => 200];
                }
                else{
                    return ['message' => 'something went wrong', 'status' => 500];
            }
                
            }

            
        
      
    }



    public function update_wishlist(Request $req){
        
        if($req->user_id =='' || $req->package_id == '' ){
            return['message'=>'can not be empty','status'=>500];
        }else{



            $wishlist = Wishlist::where('user_id', $req->user_id)->where('package_id', $req->package_id)->first();
            
            if ($wishlist) {
                // Wishlist exists, delete it
                $wishlist->delete();
                return ['message' => 'deleted', 'status' => 200];
            } else {
                // Wishlist does not exist, add it
                $newWishlist = new Wishlist();
                $newWishlist->user_id = $req->user_id;
                $newWishlist->package_id = $req->package_id;
                // Add other properties if needed
                $newWishlist->save();
                return ['message' => 'added', 'status' => 200];
            }

        }
    }





    public function enroll_course(Request $req){
        
        
        if($req->month =='' || $req->year == '' ){
            return['message'=>'Date & month can not be empty','status'=>500];
        }



        // $application = Applications::where('user_id', $req->user_id)->first();

        // if(!$application){
        //     return['message'=>'field can not be empty','field_name'=>'','status'=>421];
        // }

        // if($application->passport_number == ''){
        //     return['message'=>'field can not be empty','field_name'=>'passport_number','status'=>419];
        // }

        // if($application->passport_number == ''){
        //     return['message'=>'field can not be empty','field_name'=>'passport_number','status'=>419];
        // }

        $count_application = CourseApplication::where('user_id', $req->user_id)->get();


        if($count_application){


            if(count($count_application) >= 8){
                return['message'=>'You have reached maximum limit for apply','status'=>500];
                 
            }

        }

        return['message'=>'redirected to...','status'=>419];

        $CourseApplication = CourseApplication::where('user_id', $req->user_id)->where('course_id', $req->course_id)->first();
 if($CourseApplication){
    return['message'=>'You have already enrolled this course','status'=>500];
    
 }

        else{

            $CourseApplication = new CourseApplication();
            $CourseApplication->user_id = $req->user_id;
            $CourseApplication->course_id = $req->course_id;
            // Add other properties if needed
            if($CourseApplication->save()){
            return ['message' => 'course applied', 'status' => 200];
            }

            else{
                return['message'=>'something went wrong','status'=>500];
            }

        }
    }










    public function update_view_inst(Request $req){
        
       



            $user = User::where('user_id', $req->user_id)->first();
            
            if ($user) {
                // Wishlist exists, delete it

              
                $user->view_inst = 1;
             
                $user->save();
               // return ['message' => 'added', 'status' => 200];
                
            } 

            //return ['message' => 'added', 'status' => 200];

        }















    //     public function update_offer_letter(Request $req){
           



    //         if ($req->file == '') {
    //             return ['message' => 'File can not be empty', 'status' => 500];
    //         }

    //         $Offer_letter = Offer_letter::where('user_id', $req->user_id)->where('course_application_id', $req->package_id)->first();
            
    //         if (!$Offer_letter) {
    //           $image='';
    //           $allowedExtensions = ['pdf'];
    //           if (!in_array(strtolower($req->file('file')->getClientOriginalExtension()), $allowedExtensions)) {
    //             return ['message' => 'File must be a pdf', 'status' => 500];
    //         }
            
    //         // Check file size
    //         if ($req->file->getSize() > 1024 * 1024) {
    //             return ['message' => 'File size must be less than 1 MB', 'status' => 500];
    //         }


    //         $filePath='';

    //         if($req->file){
    //             $image = time() . '_' . Str::random(3) . '.' . $req->file->extension();
	// 		$req->file->move(public_path('assets/frontend/images/user/'), $image);
	// 		// Path to the uploaded file
    //         $filePath = public_path('assets/frontend/images/user/') . $image;
	// 	}




    //             // Get the column name dynamically based on key1 value
              
                
    //             // Update the user record with the provided key2 value and dynamic column name
    //             $Offer_letter = new Offer_letter();
                
    //             if($image != ''){
    //             $Offer_letter->file = $image;
    //             $Offer_letter->course_application_id = $req->package_id;
    //             $Offer_letter->user_id = $req->user_id;
    //             $token = Str::random(7);

    //             $Offer_letter->token = $token;
    //             }
                
    //             if($Offer_letter->save()){

    //                 CourseApplication::where('id', $req->package_id)->update(['applied_status' => 3]);
    //                 Mail::to('abhinavkumar3256@gmail.com')->send(new OfferLetter($filePath,$token,$req->user_id,$req->package_id));
    //             return ['message' => 'offer letter uploaded successfully', 'status' => 200];
    //             }
    //             else{
    //                 return ['message' => 'something went wrong', 'status' => 500];
    //         }
    
           
          
    //     }


    //     else{
    //         return ['message' => 'offer letter alreay uploaded', 'status' => 500];

    //     }
    
    // }





    public function update_offer_letter(Request $req){
           



        if ($req->file == '') {
            return ['message' => 'File can not be empty', 'status' => 500];
        }

        $Offer_letter = Offer_letter::where('user_id', $req->user_id)->where('course_application_id', $req->package_id)->first();
        
        if (!$Offer_letter) {
          $image='';
          $allowedExtensions = ['pdf'];
          if (!in_array(strtolower($req->file('file')->getClientOriginalExtension()), $allowedExtensions)) {
            return ['message' => 'File must be a pdf', 'status' => 500];
        }
        
        // Check file size
        if ($req->file->getSize() > 1024 * 1024) {
            return ['message' => 'File size must be less than 1 MB', 'status' => 500];
        }


        $filePath='';
        $api_working=0;

        if($req->file){
            $image = time() . '_' . Str::random(3) . '.' . $req->file->extension();
        $req->file->move(public_path('assets/frontend/images/user/'), $image);
        // Path to the uploaded file
        $filePath = public_path('assets/frontend/images/user/') . $image;









        $client = new \GuzzleHttp\Client();
    $headers = [
        'Authorization' => 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjdMLXZ0VDNiN2pYc2I2cUZjLVBhNyJ9.eyJodHRwczovL3NpZ25lYXN5LmNvbS9lbWFpbCI6ImFiaGluYXZAaHRsb2dpY3MuY29tIiwiaHR0cHM6Ly9zaWduZWFzeS5jb20vdXNlcl9pZCI6IjEyNTkxOTQ1IiwiaHR0cHM6Ly9zaWduZWFzeS5jb20vdGVzdF9tb2RlIjoiMSIsImlzcyI6Imh0dHBzOi8vYXV0aC5zaWduZWFzeS5jb20vIiwic3ViIjoibVl1RVF2RTZkbkZHS08yRU4weWkydUNHeHRVeTBIckhAY2xpZW50cyIsImF1ZCI6Imh0dHBzOi8vYXBpLWV4dC5zaWduZWFzeS5jb20vIiwiaWF0IjoxNzExNDI1MjY4LCJleHAiOjE3MTQwMTcyNjgsInNjb3BlIjoidXNlcjpyZWFkIGZpbGVzOnJlYWQgb3JpZ2luYWw6cmVhZCBvcmlnaW5hbDpjcmVhdGUgb3JpZ2luYWw6dXBkYXRlIHNpZ25lZDpyZWFkIHNpZ25lZDpjcmVhdGUgc2lnbmVkOnVwZGF0ZSByczpyZWFkIHJzOmNyZWF0ZSByczp1cGRhdGUgcnM6c2lnbmluZ3VybCB0ZW1wbGF0ZTptYW5hZ2Ugd2ViaG9va3M6bWFuYWdlIiwiZ3R5IjoiY2xpZW50LWNyZWRlbnRpYWxzIiwiYXpwIjoibVl1RVF2RTZkbkZHS08yRU4weWkydUNHeHRVeTBIckgifQ.lIkM8Ume6vODYf0vAgViyALKEr0YbFLF1D9yEVbHKrbTLjuKnAVCCHNXuqXF6Bblz3ewrhmqD8-yUQGPKATKfXLtcRK9rtW35plNsl7toVYXMtkLihgXnoSNmOl_6NBXd3gMDrl5J1XTs6bwl-fMBh581hHh-EBGNlR5Ni-9qXgEsQOfVfYM0oeP60idDZ3tJ8FZ2KFgzAgNvwvi1vvqnObHIvCmB9NpmigU82EyAP4VTudBMZUVMAWWSvO5niZRFJ7VON3jywShAf9HBTBYfmCSNe3l-b6SXllrwobQCJMFmf89D3wkIkIgmY9nMs_aLYzZ-qxjWJBT3qm7moqgIw',
    ];
    $options = [
        'multipart' => [
            [
                'name' => 'file',
                'contents' => fopen($filePath, 'r'),
                'filename' => $image,
            ],
            [
                'name' => 'name',
                'contents' => $image,
            ],
            [
                'name' => 'rename_if_exists',
                'contents' => '1',
            ],
        ],
    ];
    $request = new \GuzzleHttp\Psr7\Request('POST', 'https://api.signeasy.com/v3/original/', $headers);
    $res = $client->send($request, $options);

    // Extracting the ID from the API response
    $responseBody = json_decode($res->getBody(), true);
    if (isset($responseBody['id'])) {
        $receivedId = $responseBody['id'];
      //  echo "Received ID: $receivedId";
        // You can use the receivedId as needed


             // Second API call using the received ID
             $headers = [
                'Content-Type' => 'application/json',
                'Authorization' => 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjdMLXZ0VDNiN2pYc2I2cUZjLVBhNyJ9.eyJodHRwczovL3NpZ25lYXN5LmNvbS9lbWFpbCI6ImFiaGluYXZAaHRsb2dpY3MuY29tIiwiaHR0cHM6Ly9zaWduZWFzeS5jb20vdXNlcl9pZCI6IjEyNTkxOTQ1IiwiaHR0cHM6Ly9zaWduZWFzeS5jb20vdGVzdF9tb2RlIjoiMSIsImlzcyI6Imh0dHBzOi8vYXV0aC5zaWduZWFzeS5jb20vIiwic3ViIjoibVl1RVF2RTZkbkZHS08yRU4weWkydUNHeHRVeTBIckhAY2xpZW50cyIsImF1ZCI6Imh0dHBzOi8vYXBpLWV4dC5zaWduZWFzeS5jb20vIiwiaWF0IjoxNzExNDI1MjY4LCJleHAiOjE3MTQwMTcyNjgsInNjb3BlIjoidXNlcjpyZWFkIGZpbGVzOnJlYWQgb3JpZ2luYWw6cmVhZCBvcmlnaW5hbDpjcmVhdGUgb3JpZ2luYWw6dXBkYXRlIHNpZ25lZDpyZWFkIHNpZ25lZDpjcmVhdGUgc2lnbmVkOnVwZGF0ZSByczpyZWFkIHJzOmNyZWF0ZSByczp1cGRhdGUgcnM6c2lnbmluZ3VybCB0ZW1wbGF0ZTptYW5hZ2Ugd2ViaG9va3M6bWFuYWdlIiwiZ3R5IjoiY2xpZW50LWNyZWRlbnRpYWxzIiwiYXpwIjoibVl1RVF2RTZkbkZHS08yRU4weWkydUNHeHRVeTBIckgifQ.lIkM8Ume6vODYf0vAgViyALKEr0YbFLF1D9yEVbHKrbTLjuKnAVCCHNXuqXF6Bblz3ewrhmqD8-yUQGPKATKfXLtcRK9rtW35plNsl7toVYXMtkLihgXnoSNmOl_6NBXd3gMDrl5J1XTs6bwl-fMBh581hHh-EBGNlR5Ni-9qXgEsQOfVfYM0oeP60idDZ3tJ8FZ2KFgzAgNvwvi1vvqnObHIvCmB9NpmigU82EyAP4VTudBMZUVMAWWSvO5niZRFJ7VON3jywShAf9HBTBYfmCSNe3l-b6SXllrwobQCJMFmf89D3wkIkIgmY9nMs_aLYzZ-qxjWJBT3qm7moqgIw',
            ];
            $body = '{
                "embedded_signing": true,
                "is_ordered": false,
                "message": "Envelope API Demo",
                "sources": [
                    {
                        "id": ' . $receivedId . ',
                        "type": "original",
                        "name": "pqr",
                        "source_id": 1
                    }
                ],
                "recipients": [
                    {
                        "first_name": "Amann",
                        "last_name": "Jhamb",
                        "email": "abhinav@htlogics.com",
                        "recipient_id": 1
                    }
                ],
                "signature_panel_types": [
                    "draw",
                    "type"
                ],
                "initial_panel_types": [
                    "draw"
                ],
                "fields_payload": [
                    {
                        "recipient_id": 1,
                        "source_id": 1,
                        "type": "signature",
                        "required": true,
                        "page_number": "all",
                        "position": {
                            "height": 100,
                            "width": 100,
                            "x": 400,
                            "y": 200,
                            "mode": "fixed"
                        },
                        "additional_info": {}
                    }
                ]
            }';
            $request = new \GuzzleHttp\Psr7\Request('POST', 'https://api.signeasy.com/v3/rs/envelope/', $headers, $body);
            $res = $client->send($request);
        

            $responseBody = json_decode($res->getBody(), true);
            if (isset($responseBody['id'])) {
                $receivedId2 = $responseBody['id'];
    
                // Third API call using the second received ID
                $headers = [
                    'Content-Type' => 'application/json',
                    'Authorization' => 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjdMLXZ0VDNiN2pYc2I2cUZjLVBhNyJ9.eyJodHRwczovL3NpZ25lYXN5LmNvbS9lbWFpbCI6ImFiaGluYXZAaHRsb2dpY3MuY29tIiwiaHR0cHM6Ly9zaWduZWFzeS5jb20vdXNlcl9pZCI6IjEyNTkxOTQ1IiwiaHR0cHM6Ly9zaWduZWFzeS5jb20vdGVzdF9tb2RlIjoiMSIsImlzcyI6Imh0dHBzOi8vYXV0aC5zaWduZWFzeS5jb20vIiwic3ViIjoibVl1RVF2RTZkbkZHS08yRU4weWkydUNHeHRVeTBIckhAY2xpZW50cyIsImF1ZCI6Imh0dHBzOi8vYXBpLWV4dC5zaWduZWFzeS5jb20vIiwiaWF0IjoxNzExNDI1MjY4LCJleHAiOjE3MTQwMTcyNjgsInNjb3BlIjoidXNlcjpyZWFkIGZpbGVzOnJlYWQgb3JpZ2luYWw6cmVhZCBvcmlnaW5hbDpjcmVhdGUgb3JpZ2luYWw6dXBkYXRlIHNpZ25lZDpyZWFkIHNpZ25lZDpjcmVhdGUgc2lnbmVkOnVwZGF0ZSByczpyZWFkIHJzOmNyZWF0ZSByczp1cGRhdGUgcnM6c2lnbmluZ3VybCB0ZW1wbGF0ZTptYW5hZ2Ugd2ViaG9va3M6bWFuYWdlIiwiZ3R5IjoiY2xpZW50LWNyZWRlbnRpYWxzIiwiYXpwIjoibVl1RVF2RTZkbkZHS08yRU4weWkydUNHeHRVeTBIckgifQ.lIkM8Ume6vODYf0vAgViyALKEr0YbFLF1D9yEVbHKrbTLjuKnAVCCHNXuqXF6Bblz3ewrhmqD8-yUQGPKATKfXLtcRK9rtW35plNsl7toVYXMtkLihgXnoSNmOl_6NBXd3gMDrl5J1XTs6bwl-fMBh581hHh-EBGNlR5Ni-9qXgEsQOfVfYM0oeP60idDZ3tJ8FZ2KFgzAgNvwvi1vvqnObHIvCmB9NpmigU82EyAP4VTudBMZUVMAWWSvO5niZRFJ7VON3jywShAf9HBTBYfmCSNe3l-b6SXllrwobQCJMFmf89D3wkIkIgmY9nMs_aLYzZ-qxjWJBT3qm7moqgIw',
                ];
                $body = '{
                    "recipient_email": "abhinav@htlogics.com",
                    "redirect_url": "https://www.signeasy.com/api"
                }';
                $request = new \GuzzleHttp\Psr7\Request('POST', 'https://api.signeasy.com/v3/rs/envelope/' . $receivedId2 . '/signing/url/', $headers, $body);
             //   $res = $client->send($request);
              
                $res = $client->send($request);
                $responseBody = json_decode($res->getBody(), true);
                if (isset($responseBody['url'])) {
                    $signingUrl = $responseBody['url'];
                    //echo "Signing URL: $signingUrl";

                    $api_working=1;
                } else {
                   // echo "URL not found in the API response";

                   return ['message' => 'something went wrong', 'status' => 500];
                }
            } else {
                //echo "Second ID not found in the API response";
                return ['message' => 'something went wrong', 'status' => 500];
            }



        } else {
           // echo "ID not found in the API response";
           return ['message' => 'something went wrong', 'status' => 500];
        }
   
    }




            // Get the column name dynamically based on key1 value
          
            if($api_working== 1){
            // Update the user record with the provided key2 value and dynamic column name
            $Offer_letter = new Offer_letter();
            
            if($image != ''){
            $Offer_letter->file = $image;
            $Offer_letter->course_application_id = $req->package_id;
            $Offer_letter->user_id = $req->user_id;
            $Offer_letter->url=$signingUrl;
            $token = Str::random(7);

            $Offer_letter->token = $token;
            }
            
            if($Offer_letter->save()){

                // CourseApplication::where('id', $req->package_id)->update(['applied_status' => 3]);


                CourseApplication::where('id', $req->package_id)->update([
                    'applied_status' => 3,
                    'receivedId2' => $receivedId2,
                    'receivedId' => $receivedId,
                    'signingUrl' => $signingUrl,
                    'offer_letter_path' => $image,
                   
                    // Add more fields as needed
                ]);
                Mail::to('abhinavkumar3256@gmail.com')->send(new OfferLetter($filePath,$token,$req->user_id,$req->package_id));
            return ['message' => 'offer letter uploaded successfully', 'status' => 200];
            }
            else{
                return ['message' => 'something went wrong', 'status' => 500];
        }

    }
    else{
        return ['message' => 'something went wrong', 'status' => 500];
    }

       
      
    }


    else{
        return ['message' => 'offer letter alreay uploaded', 'status' => 500];

    }

}


public function download_offer_letter(){

    $client = new \GuzzleHttp\Client();
    // Third API call using the second received ID
    $headers = [
        'Content-Type' => 'application/json',
        'Authorization' => 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjdMLXZ0VDNiN2pYc2I2cUZjLVBhNyJ9.eyJodHRwczovL3NpZ25lYXN5LmNvbS9lbWFpbCI6ImFiaGluYXZAaHRsb2dpY3MuY29tIiwiaHR0cHM6Ly9zaWduZWFzeS5jb20vdXNlcl9pZCI6IjEyNTkxOTQ1IiwiaHR0cHM6Ly9zaWduZWFzeS5jb20vdGVzdF9tb2RlIjoiMSIsImlzcyI6Imh0dHBzOi8vYXV0aC5zaWduZWFzeS5jb20vIiwic3ViIjoibVl1RVF2RTZkbkZHS08yRU4weWkydUNHeHRVeTBIckhAY2xpZW50cyIsImF1ZCI6Imh0dHBzOi8vYXBpLWV4dC5zaWduZWFzeS5jb20vIiwiaWF0IjoxNzExNDI1MjY4LCJleHAiOjE3MTQwMTcyNjgsInNjb3BlIjoidXNlcjpyZWFkIGZpbGVzOnJlYWQgb3JpZ2luYWw6cmVhZCBvcmlnaW5hbDpjcmVhdGUgb3JpZ2luYWw6dXBkYXRlIHNpZ25lZDpyZWFkIHNpZ25lZDpjcmVhdGUgc2lnbmVkOnVwZGF0ZSByczpyZWFkIHJzOmNyZWF0ZSByczp1cGRhdGUgcnM6c2lnbmluZ3VybCB0ZW1wbGF0ZTptYW5hZ2Ugd2ViaG9va3M6bWFuYWdlIiwiZ3R5IjoiY2xpZW50LWNyZWRlbnRpYWxzIiwiYXpwIjoibVl1RVF2RTZkbkZHS08yRU4weWkydUNHeHRVeTBIckgifQ.lIkM8Ume6vODYf0vAgViyALKEr0YbFLF1D9yEVbHKrbTLjuKnAVCCHNXuqXF6Bblz3ewrhmqD8-yUQGPKATKfXLtcRK9rtW35plNsl7toVYXMtkLihgXnoSNmOl_6NBXd3gMDrl5J1XTs6bwl-fMBh581hHh-EBGNlR5Ni-9qXgEsQOfVfYM0oeP60idDZ3tJ8FZ2KFgzAgNvwvi1vvqnObHIvCmB9NpmigU82EyAP4VTudBMZUVMAWWSvO5niZRFJ7VON3jywShAf9HBTBYfmCSNe3l-b6SXllrwobQCJMFmf89D3wkIkIgmY9nMs_aLYzZ-qxjWJBT3qm7moqgIw',
    ];
    // $body = '{
    //     "recipient_email": "abhinav@htlogics.com",
    //     "redirect_url": "https://www.signeasy.com/api"
    // }';
    $request = new \GuzzleHttp\Psr7\Request('GET', 'https://api.signeasy.com/v3/signed/94776253/download?type=merged&include_certificate=true', $headers);
 //   $res = $client->send($request);
  

 $res = $client->sendAsync($request)->wait();

 print_r($res);
    // $res = $client->send($request);
    // $responseBody = json_decode($res->getBody(), true);


  // Save the downloaded PDF file locally
  $localFilePath = public_path('assets/frontend/images/user/') . 'downloaded.pdf';
  file_put_contents($localFilePath, $res->getBody());



}



public function handleWebhook(Request $request)
{
    // Validate incoming webhook data if needed

    // Assuming the webhook data is in JSON format
    $data = $request->all();

   
 

    // Save the data to the database
   // $response = isset($data['response']) ? $data['response'] : null;

    // Save the data to the database
    // $response = isset($data['response']) ? $data['response'] : null;

  $cronResponce = new Cron_responce();
 $cronResponce->response = json_encode($data);
   

   if( $cronResponce->save()){

    $insertedId = $cronResponce->id;




    $inserteddata = Cron_responce::where('id', $insertedId)->first();
    $responseData = json_decode($inserteddata['response'], true);

// Extract the signed_file_id
$signedFileId = $responseData['data']['signed_file_id'];



if($signedFileId){




    $client = new \GuzzleHttp\Client();
    // Third API call using the second received ID
    $headers = [
        'Content-Type' => 'application/json',
        'Authorization' => 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjdMLXZ0VDNiN2pYc2I2cUZjLVBhNyJ9.eyJodHRwczovL3NpZ25lYXN5LmNvbS9lbWFpbCI6ImFiaGluYXZAaHRsb2dpY3MuY29tIiwiaHR0cHM6Ly9zaWduZWFzeS5jb20vdXNlcl9pZCI6IjEyNTkxOTQ1IiwiaHR0cHM6Ly9zaWduZWFzeS5jb20vdGVzdF9tb2RlIjoiMSIsImlzcyI6Imh0dHBzOi8vYXV0aC5zaWduZWFzeS5jb20vIiwic3ViIjoibVl1RVF2RTZkbkZHS08yRU4weWkydUNHeHRVeTBIckhAY2xpZW50cyIsImF1ZCI6Imh0dHBzOi8vYXBpLWV4dC5zaWduZWFzeS5jb20vIiwiaWF0IjoxNzExNDI1MjY4LCJleHAiOjE3MTQwMTcyNjgsInNjb3BlIjoidXNlcjpyZWFkIGZpbGVzOnJlYWQgb3JpZ2luYWw6cmVhZCBvcmlnaW5hbDpjcmVhdGUgb3JpZ2luYWw6dXBkYXRlIHNpZ25lZDpyZWFkIHNpZ25lZDpjcmVhdGUgc2lnbmVkOnVwZGF0ZSByczpyZWFkIHJzOmNyZWF0ZSByczp1cGRhdGUgcnM6c2lnbmluZ3VybCB0ZW1wbGF0ZTptYW5hZ2Ugd2ViaG9va3M6bWFuYWdlIiwiZ3R5IjoiY2xpZW50LWNyZWRlbnRpYWxzIiwiYXpwIjoibVl1RVF2RTZkbkZHS08yRU4weWkydUNHeHRVeTBIckgifQ.lIkM8Ume6vODYf0vAgViyALKEr0YbFLF1D9yEVbHKrbTLjuKnAVCCHNXuqXF6Bblz3ewrhmqD8-yUQGPKATKfXLtcRK9rtW35plNsl7toVYXMtkLihgXnoSNmOl_6NBXd3gMDrl5J1XTs6bwl-fMBh581hHh-EBGNlR5Ni-9qXgEsQOfVfYM0oeP60idDZ3tJ8FZ2KFgzAgNvwvi1vvqnObHIvCmB9NpmigU82EyAP4VTudBMZUVMAWWSvO5niZRFJ7VON3jywShAf9HBTBYfmCSNe3l-b6SXllrwobQCJMFmf89D3wkIkIgmY9nMs_aLYzZ-qxjWJBT3qm7moqgIw',
    ];
 
    $request = new \GuzzleHttp\Psr7\Request('GET', 'https://api.signeasy.com/v3/signed/'.$signedFileId.'/download?type=merged&include_certificate=true', $headers);

  

 $res = $client->sendAsync($request)->wait();




 $randomString = substr(md5(uniqid()), 0, 4);  // Generate 4 random letters
 $fileName = $randomString . '_offer.pdf'; // Append "_offer.pdf" to the random letters
 
 $localFilePath = public_path('assets/frontend/images/user/') . $fileName;
  file_put_contents($localFilePath, $res->getBody());





CourseApplication::where('receivedId2', $signedFileId)->update([
    'applied_status' => 4,
    'sign_offer_letter_path'=> $fileName,
   
   
    // Add more fields as needed
]);



  //  if($college){
    return response()->json(['message' => 'Webhook data saved successfully'], 200);
   }else{

   return response()->json(['message' => 'Webhook data not saved'], 500);
   }
}
   else{
   return response()->json(['message' => 'Webhook data not saved'], 500);
   }

  //echo $cronResponce->getError();
}


}