<?php 




  
include("./Connections/conn.php");
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {  die("Connection failed: " . $conn->connect_error); }


$uistr = $_GET["uuid_str"];






$First_Name  = " ";
$Middle_Name  = " ";
$Last_Name  = " ";
$Suffix  = " ";
$Date_of_Birth  = " ";
$SSN   = " ";
$useremail  = " ";
$phoneNumber  = " ";


$Street_Address  = " ";
$City  = " ";
$State  = " ";
$Zip_Code   = " ";




 
  
    $conn = new mysqli($servername, $username, $password, $dbname);
    if ($conn->connect_error) {  die("Connection failed: " . $conn->connect_error); }

    

    $query = " select  *
    from applications 
    where applications.`uuid_str` = '". $uistr ."'  "; 
   // echo  $query;

    mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
    $mysqli = new mysqli($servername, $username, $password, $dbname);
    $stmt = $mysqli->prepare( $query );
    // $stmt->bind_param("s",  $_GET["Payroll_Number"] );

    $stmt->execute();
    $result = $stmt->get_result(); 
    $FullColumnData = "";

    while ($row = $result->fetch_assoc()) {
     
       
  
        $First_Name  = $row["First_Name"]." ";
        $Middle_Name  = $row["Middle_Name"]." ";
        $Last_Name  = $row["Last_Name"]." ";
        $Suffix  = $row["Suffix"]." ";
        $Date_of_Birth  = $row["Date_of_Birth"]." ";
        $SSN  = $row["SSN"]." ";
        $useremail  = $row["useremail"]." ";
        $phoneNumber  = $row["phoneNumber"]." ";
        $Street_Address  = $row["Street_Address"]." ";
        $City  = $row["City"]." ";
        $State  = $row["State"]." ";
        $Zip_Code  = $row["Zip_Code"]." ";

    }












    
 

$Business_Name = "";

$Business_Type = "";
$Business_Address = "";
$Business_Address_City = "";
$Business_Address_State = "";
$Business_Address_ZipCode = "";
$EID_Number = "";
$businessEstablished = "";
$phoneBusinessPhoneNumber = "";
$Professional_Business_Email = "";

$dnbNumber = "";
$dnbUsername = "";
$dnbPassword = "";
$nav_username = "";
$nav_password = "";


 
  
    $conn = new mysqli($servername, $username, $password, $dbname);
    if ($conn->connect_error) {  die("Connection failed: " . $conn->connect_error); }

    

    $query = " select  *
    from Step3_Business 
    where Step3_Business.`uuid_str` = '". $uistr ."'  "; 
   // echo  $query;

    mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
    $mysqli = new mysqli($servername, $username, $password, $dbname);
    $stmt = $mysqli->prepare( $query );
    // $stmt->bind_param("s",  $_GET["Payroll_Number"] );

    $stmt->execute();
    $result = $stmt->get_result(); 
    $FullColumnData = "";

    while ($row = $result->fetch_assoc()) {
      
 

        $Business_Name  = $row["Business_Name"] . " ";

        $Business_Type  = $row["Business_Type"] . " ";
        $Business_Address  = $row["Business_Address"] . " ";
        $Business_Address_City  = $row["Business_Address_City"] . " ";
        $Business_Address_State  = $row["Business_Address_State"] . " ";
        $Business_Address_ZipCode  = $row["Business_Address_ZipCode"] . " ";
        $EID_Number  = $row["EID_Number"] . " ";
        $businessEstablished  = $row["businessEstablished"] . " ";
        $phoneBusinessPhoneNumber  = $row["phoneBusinessPhoneNumber"] . " ";

        $Professional_Business_Email= $row["Professional_Business_Email"] . " ";


        $dnbNumber  = $row["dnbNumber"] . " ";
        $dnbUsername  = $row["dnbUsername"] . " ";
        $dnbPassword  = $row["dnbPassword"] . " ";
        $nav_username  = $row["nav_username"] . " ";
        $nav_password  = $row["nav_password"] . " ";

    }


 
 
 




    $stmt->close(); 
    $conn->close(); 

   










    $Security_Question_Exp  = "";
    $Security_Answer_Exp  = $row["Security_Answer_Exp"];
    $Pin_Exp   = "";










 
  
    $conn = new mysqli($servername, $username, $password, $dbname);
    if ($conn->connect_error) {  die("Connection failed: " . $conn->connect_error); }

    

    $query = " select  *
    from credit_report 
    where credit_report.`uuid_str` = '". $uistr ."'  "; 
   // echo  $query;

    mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
    $mysqli = new mysqli($servername, $username, $password, $dbname);
    $stmt = $mysqli->prepare( $query );
    // $stmt->bind_param("s",  $_GET["Payroll_Number"] );

    $stmt->execute();
    $result = $stmt->get_result(); 
    $FullColumnData = "";

    while ($row = $result->fetch_assoc()) {
       

        
        $User_Name  = $row["User_Name"];
        $_Password  = $row["_Password"];
        $User_NameExp  = $row["User_NameExp"];
        $_PasswordExp  = $row["_PasswordExp"];

        $Security_Question_Exp  = $row["Security_Question_Exp"];
        $Security_Answer_Exp  = $row["Security_Answer_Exp"];
        $Pin_Exp  = $row["Pin_Exp"];


        $User_NameKarma  = $row["User_NameKarma"];
        $PasswordKarma  = $row["PasswordKarma"];
        

        


    }

 


    $stmt->close(); 
    $conn->close(); 

   



 















  

 



// https://docs.google.com/spreadsheets/d/1jH2e0Ifd6BDrYQM4G7Gv9QyIx8Oo6RvIfd2RwaVpveA/edit?gid=0#gid=0

require __DIR__ . '/vendor/autoload.php';

$client = new \Google_Client();
$client->setApplicationName('Google Sheets with Primo');
$client->setScopes([\Google_Service_Sheets::SPREADSHEETS]);
$client->setAccessType('offline');
$client->setAuthConfig(__DIR__ . '/credentialM.json');

$service = new Google_Service_Sheets($client);
$spreadsheetId = "1jH2e0Ifd6BDrYQM4G7Gv9QyIx8Oo6RvIfd2RwaVpveA";

$range = "Sheet1"; // Sheet name



 
 

































function updateSpecificColumns($spreadsheetId, $emailToFind, $newValues) {


    $credentialsPath = './credentialM.json';
    

    $client = new Google_Client();
    $client->setApplicationName('Google Sheets API PHP');
    $client->setScopes([Google_Service_Sheets::SPREADSHEETS]);
    $client->setAuthConfig($credentialsPath);
    
    $service = new Google_Service_Sheets($client);
    
    $range = 'Sheet1'; 
    $response = $service->spreadsheets_values->get($spreadsheetId, $range);
    $values = $response->getValues();
    
    if (empty($values)) {
       echo "Nodata found in the sheet.\n";
        return;
    }    


    $emailColumnIndex = 4; 
    $rowIndexToUpdate  =  -1;
    
    foreach($values as $rowIndex => $row) {
        if(isset($row[$emailColumnIndex]) && $row[$emailColumnIndex] === $emailToFind) {
            $rowIndexToUpdate = $rowIndex;
            break;
        }
    }
    
    if($rowIndexToUpdate === -1) {
     return;
    }
    
    $columnsToUpdate = ['AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH' , 'AI' , 'AJ' , 'AK' , 'AL', 'AM', 'AN' , 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU'];
    $updateRange = 'Sheet1!'.$columnsToUpdate[0] . ($rowIndexToUpdate + 1) . ':' . end($columnsToUpdate) . ($rowIndexToUpdate + 1);
    
    $body = new Google_Service_Sheets_ValueRange([
    'values' => [$newValues]
    ]);
    $params = ['valueInputOption' => 'RAW'];
    

    $service->spreadsheets_values->update($spreadsheetId, $updateRange, $body, $params);
    
    }
    
    // Replace with your Google Sheet ID
    $spreadsheetId = '1jH2e0Ifd6BDrYQM4G7Gv9QyIx8Oo6RvIfd2RwaVpveA';
     

 


    $newValues = [$nav_username, $nav_password, $dnbNumber, $dnbUsername , $dnbPassword, $User_NameKarma ,  $PasswordKarma , $User_Name ,  $_Password, $User_NameExp ,
    $_PasswordExp , $Security_Question_Exp  ,  $Security_Answer_Exp ,  $Pin_Exp , $User_NameKarma ,  $PasswordKarma, " ", " ", " ", $SSN ]; 
    
 

    
    
    


    updateSpecificColumns($spreadsheetId, $useremail, $newValues);
 

    header("Location: https://app.bfffunding.net/PersonalInformation/Credit-Information");

    
header("Location: https://calendly.com/businessfundingfirm");

?>