<?php
    session_start();
    if (!isset($_SESSION['username'])) {
        header("Location: login.php");
        exit();
    }
    
    require_once('include/config.php');
    require_once('include/startup.php');                           
    $alltables = new AllTables();
    
    // View Correspondence Address
    $sql="SELECT * FROM contact_person where cmp_id = $G_companyid ";
    $result = $conn->query($sql);
    
    $contactperson="";
    
    while($rows = $result->fetch_assoc()) {
        
        $cardId = $rows['id']; // unique DB id
        $designation = $rows['designation'];
        
        $selAccountant   = ($designation == 'Accountant') ? 'selected' : '';
        $selChairperson = ($designation == 'Chairperson') ? 'selected' : '';
        $selContact     = ($designation == 'Contact Person') ? 'selected' : '';
        $selMarketing   = ($designation == 'Marketing Head') ? 'selected' : '';
         
        $contactperson .= "<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'>Contact Person</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-contact-person.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'>Contact Person:</th>
                                                            <td class='view-mode'>". $rows['name']."</td>
                                                            <td><input id='txt_cp_name' name='txt_cp_name' class='form-control edit-mode' type='text' placeholder='Enter PAN No' aria-label='.form-control-sm example' value='".$rows['name']."'></td>
                                                        </tr>
                                                        <tr>
                                                            <th scope='row'>Designation:</th>
                                                            <td class='view-mode'>". $rows['designation']."</td>
                                                            <td>
                                                                <select id='txt_cp_type' name='txt_cp_type' class='form-select edit-mode' aria-label='Default select example'>
                                                                    <option value='' hidden>Select Contact Type</option>           
                                                                    <option value='Accountant' $selAccountant>Accountant</option>
                                                                    <option value='Chairperson' $selChairperson>Chairperson</option>    
                                                                    <option value='Contact Person' $selContact>Contact Person</option>
                                                                    <option value='Marketing Head' $selMarketing>Marketing Head</option>
                                                                </select>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <th scope='row'>Email:</th>
                                                            <td class='view-mode'>". $rows['email']."</td>
                                                            <td><input id='txt_cp_email' name='txt_cp_email' class='form-control edit-mode' type='text' placeholder='Enter PAN No' aria-label='.form-control-sm example' value='".$rows['email']."'></td>
                                                        </tr>
                                                        <tr>
                                                            <th scope='row'>Mobile No:</th>
                                                            <td class='view-mode'>". $rows['mobile_no']."</td>
                                                            <td><input id='txt_cp_contactno' name='txt_cp_contactno' class='form-control edit-mode' type='text' placeholder='Enter PAN No' aria-label='.form-control-sm example' value='".$rows['mobile_no']."'></td>
                                                        </tr>
                                                        <tr>
                                                            <th scope='row'>Whatsapp Number:</th>
                                                            <td class='view-mode'>". $rows['whatsapp_no']."</td>
                                                            <td><input id='txt_cp_whatsapp' name='txt_cp_whatsapp' class='form-control edit-mode' type='text' placeholder='Enter PAN No' aria-label='.form-control-sm example' value='".$rows['whatsapp_no']."'></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('include/header.php');   
    include_once('contact-person1.html');
    include('include/footer.php');         
?>    