<?php
    session_start();
    if (!isset($_SESSION['username'])) {
        $_SESSION['login_msg'] = "Please login first to continue.";
        header("Location: login.php");
        exit();
    }
    
    require_once('include/config.php');
    require_once('include/startup.php');                           
    $alltables = new AllTables();
    
    
    include('include/header.php');  
    
    $sql="SELECT * FROM mst_company WHERE id = $G_companyid";      
    $data = $alltables -> getInfo('',$sql);  
    
    $address                = $data[0]['address'];
    $country                = $data[0]['country'];
    $state                  = $data[0]['state'];
    $city                   = $data[0]['city'];
    $pincode                = $data[0]['pincode'];       
    
    
    
    // View Correspondence Address
    $sql="SELECT * FROM correspondence_address where cmp_id = $G_companyid ";
    $result = $conn->query($sql);
    
    $companyaddress="";
    
    while($rows = $result->fetch_assoc()) {
        
         $cardId = $rows['id']; // unique DB id
         
        $companyaddress .= "
                            <div class='col-md-6 mb-4'>
                                <div class='card overviwe-card' id='card-$cardId' style='min-height: 20rem;'>
                                    <div class='card-body'>
                                        <div class='row'>
                                            <div class='col-md-12 mb-3'>
                                                <h5 class='mb-2 title2'>Correspondence Address</h5>
                                                <!--<small class='small-b'>Please fill the following forms to complete your Profile.</small>-->
                                            </div>
                                            <div class='col-md-12'>
                                                <table class='table' style='max-height: 18rem; overflow-y: auto;'>
                                                    <tbody>
                                                        <form action='add-correspondence-address.php' method='post'>
                                                            <input id='txt_id' name='txt_id' class='form-control edit-mode' type='hidden' aria-label='.form-control-sm example' value='".$rows['id']."'>
                                                            <tr>
                                                                <th scope='row'>Address:</th>
                                                                <td class='view-mode'>". $rows['address']."</td>
                                                                <td><input id='txt_address' name='txt_address' class='form-control edit-mode' type='text' placeholder='Enter PAN No' aria-label='.form-control-sm example' value='".$rows['address']."'></td>
                                                            </tr>
                                                            <tr>
                                                                <th  scope='row'>Country:</th>
                                                                <td class='view-mode'>". $rows['country']."</td>
                                                                <td><input id='txt_country' name='txt_country' class='form-control edit-mode' type='text' placeholder='Enter PAN No' aria-label='.form-control-sm example' value='".$rows['country']."'></td>
                                                            </tr>
                                                            <tr>
                                                                <th scope='row'>State:</th>
                                                                <td class='view-mode'>". $rows['state']."</td>
                                                                <td><input id='txt_state' name='txt_state' class='form-control edit-mode' type='text' placeholder='Enter PAN No' aria-label='.form-control-sm example' value='".$rows['state']."'></td>
                                                            </tr>
                                                            <tr>
                                                                <th scope='row'>City:</th>
                                                                <td class='view-mode'>". $rows['city']."</td>
                                                                <td><input id='txt_city' name='txt_city' class='form-control edit-mode' type='text' placeholder='Enter PAN No' aria-label='.form-control-sm example' value='".$rows['city']."'></td>
                                                            </tr>
                                                            <tr>
                                                                <th scope='row'>Pincode:</th>
                                                                <td class='view-mode'>". $rows['pincode']."</td>
                                                                <td><input id='txt_pincode' name='txt_pincode' class='form-control edit-mode' type='text' placeholder='Enter PAN No' aria-label='.form-control-sm example' value='".$rows['pincode']."'></td>
                                                            </tr>
                                                            <tr>
                                                                <td colspan='2'>
                                                                    <div class='col-md-12 d-flex justify-content-end'>
                                                                        <button type='button' class='btn btn-sm btn-danger me-2 edit-mode' onclick='cancelEdit($cardId)'>Cancel</button>
                                                                        <input name='btn-edit' type='submit' class='btn btn-sm btn-success edit-mode' value='Submit'>
                                                                        <button type='button' class='btn btn-sm btn-primary view-mode' onclick='editCard($cardId)'>Edit</button>     
                                                                    </div>
                                                                </td>
                                                            </tr>
                                                        </form>    
                                                    </tbody>
                                                </table>  
                                            </div>
                                        </div>  
                                    </div>
                                </div>
                            </div>     
                            ";
    }
    
     
    include_once('company-address1.html');   
    include('include/footer.php');         
?>    