<?php
include_once('../includes/DB/Connection.php');
include_once('../student/classes/Student.php');
include_once('../student/includes/update-profile.php');

//session_start();
//session_destroy();
if (session_status() == PHP_SESSION_NONE) {
    session_start();
}

if (isset($_SESSION['log_session']) && !empty($_SESSION['log_session'] && $_SESSION['log_session']['user_role_id'] == '5')) {
    // Student

    $user_id = $_SESSION['log_session']['user_id'];
    $user_role_name = $_SESSION['log_session']['user_role_name'];
    $user_role_id = $_SESSION['log_session']['user_role_id'];
    $user_first_name =  $_SESSION['log_session']['user_first_name'];
} else {
    header('Location: ../login.php');
    exit();
}

?>

<!DOCTYPE html>
<html lang='en'>

<head>

    <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <meta name='description'
        content='Multikart admin is super flexible, powerful, clean &amp; modern responsive bootstrap 4 admin template with unlimited possibilities.'>
    <meta name='keywords'
        content='admin template, Multikart admin template, dashboard template, flat admin template, responsive admin template, web app'>
    <meta name='author' content='pixelstrap'>
    <link rel='icon' href='../assets/images/dashboard/favicon.png' type='image/x-icon'>
    <link rel='shortcut icon' href='../assets/images/dashboard/favicon.png' type='image/x-icon'>
    <title>AIC/IMC - Student Profile</title>

    <!-- Google font-->
    <link rel='stylesheet'
        href='https://fonts.googleapis.com/css2?family=Work+Sans:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,500;1,600;1,700;1,800;1,900&display=swap'>

    <link rel='stylesheet'
        href='https://fonts.googleapis.com/css2?family=Nunito:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap'>

    <!-- Font Awesome-->
    <link rel='stylesheet' type='text/css' href='../assets/css/vendors/font-awesome.css'>

    <!-- Flag icon-->
    <link rel='stylesheet' type='text/css' href='../assets/css/vendors/flag-icon.css'>

    <!-- Bootstrap css-->
    <link rel='stylesheet' type='text/css' href='../assets/css/vendors/bootstrap.css'>

    <!-- App css-->
    <link rel='stylesheet' type='text/css' href='../assets/css/style.css'>

    <!-- Include SweetAlert CSS -->
    <link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css'>

    <!-- Include SweetAlert JS -->
    <script src='https://cdn.jsdelivr.net/npm/sweetalert2@11'></script>

    <script>
    function togglePhoneInput() {
        var form = document.getElementById('phoneForm');
        form.style.display = (form.style.display === 'none') ? 'block' : 'none';
    }

    function validatePhone() {
        var phone3 = document.getElementById('phoneInput3').value;
        return true;
    }

    function toggleGenderInput() {
        var phoneForm = document.getElementById('phoneForm');
        var phoneDisplay = document.getElementById('phoneDisplay');
        if (phoneForm.style.display === 'none') {
            phoneForm.style.display = 'block';
            phoneDisplay.style.display = 'none';
        } else {
            phoneForm.style.display = 'none';
            phoneDisplay.style.display = 'block';
        }
    }
    </script>

</head>

<body>

    <!-- page-wrapper Start-->
    <div class='page-wrapper'>

        <!-- page-header Start-->
        <?php include('../includes/headers/header.php');
        ?>
        <!-- page-header end-->

        <!-- Page Body Start-->
        <div class='page-body-wrapper'>

            <!-- Page Sidebar Start-->
            <?php include('../includes/Sidebar/sidebar.php');
            ?>
            <!-- Page Sidebar Ends-->

            <!-- Right sidebar Start-->
            <?php include('../includes/rightsidebar/rightsiderbar.php');
            ?>
            <!-- Right sidebar Ends-->

            <div class='page-body'>
                <!-- Container-fluid starts-->
                <div class='container-fluid'>
                    <div class='page-header'>
                        <div class='row'>
                            <div class='col-lg-6'>
                                <div class='page-header-left'>
                                    <h3>Profile
                                        <small>AIC/IMC</small>
                                    </h3>
                                </div>
                            </div>
                            <div class='col-lg-6'>
                                <ol class='breadcrumb pull-right'>
                                    <li class='breadcrumb-item'>
                                        <a href='./dashboard.php'>
                                            <i data-feather='home'></i>
                                        </a>
                                    </li>
                                    <li class='breadcrumb-item'>Settings</li>
                                    <li class='breadcrumb-item active'>Profile</li>
                                </ol>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- Container-fluid Ends-->

                <!-- Container-fluid starts-->
                <div class='container-fluid'>
                    <div class='row'>

                        <div class='col-xl-12'>
                            <div class='card tab2-card'>
                                <div class='card-body'>
                                    <div class='tab-content' id='top-tabContent'>
                                        <div class='tab-pane fade show active' id='top-profile' role='tabpanel'
                                            aria-labelledby='top-profile-tab'>
                                            <h5 class='f-w-600'></h5>
                                            <div class='table-responsive profile-table'>
                                                <table class='table table-borderless' style='font-size: 14px;'>
                                                    <tbody>

                                                        <div class=' profile-details text-center'>
                                                            <img src='assets/images/image.png' alt=''
                                                                class='img-fluid img-90 rounded-circle blur-up lazyloaded'>
                                                            <h5 class='f-w-600 mb-0'>
                                                                <?php echo $studentDetails['student_first_name'] . ' ' . $studentDetails['student_last_name'];
                                                                ?>

                                                            </h5>
                                                            <?php echo $studentDetails['student_email'];
                                                            ?>
                                                            <div class='social'>
                                                                <div class='form-group btn-showcase'>
                                                                    <button
                                                                        class='btn social-btn btn-fb d-inline-block'> <i
                                                                            class='fa fa-facebook'></i></button>
                                                                    <button
                                                                        class='btn social-btn btn-twitter d-inline-block'><i
                                                                            class='fa fa-google'></i></button>
                                                                    <button
                                                                        class='btn social-btn btn-google d-inline-block me-0'><i
                                                                            class='fa fa-twitter'></i></button>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <?php
                                                        if ($studentDetails !== null) {
                                                        ?>

                                                        <tr>
                                                            <td>
                                                                <strong>First Name:</strong>
                                                            </td>
                                                            <td><?php echo $studentDetails['student_first_name'];
                                                                    ?>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td><strong>Last Name:</strong></td>
                                                            <td><?php echo $studentDetails['student_last_name'];
                                                                    ?></td>
                                                        </tr>
                                                        <tr>
                                                            <td><strong>Gender:</strong></td>
                                                            <td><?php echo $studentDetails['student_gender'];
                                                                    ?></td>
                                                            <td>
                                                                <form method='post'>
                                                                    <input type='radio' name='gender' value='Male'
                                                                        <?php echo $studentDetails['student_gender'] === 'Male' ? 'checked' : '';
                                                                                                                        ?> required> Male
                                                                    <input type='radio' name='gender' value='Female'
                                                                        <?php echo $studentDetails['student_gender'] === 'Female' ? 'checked' : '';
                                                                                                                            ?> required> Female
                                                            <td><button type='submit'
                                                                    class='btn btn-primary upload-btn'>Update</button>
                                                            </td>
                                                            </form>

                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td><strong>Email:</strong></td>
                                                            <td><?php echo $studentDetails['student_email'];
                                                                    ?></td>

                                                            </form>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td><strong>Nic or Passport Id:</strong></td>
                                                            <td><?php echo $studentDetails['student_nic_or_passport_id'];
                                                                    ?>
                                                            </td>
                                                        </tr>

                                                        <tr>
                                                            <td><strong>Contact No:</strong></td>
                                                            <td>
                                                                <span id='phoneDisplay'><?php echo htmlspecialchars($studentDetails['student_phone_1']) . ' , ' . htmlspecialchars($studentDetails['student_phone_2']);
                                                                                            ?></span>
                                                            </td>
                                                            <td>
                                                                <a href='javascript:void(0);'
                                                                    onclick='togglePhoneInput()'>add from
                                                                    here</a>
                                                                <form method='post' id='phoneForm' style='display:none;'
                                                                    onsubmit='return validatePhone()'>
                                                                    <input type='text' name='phone3' id='phoneInput3'
                                                                        placeholder='Add new phone number'>
                                                                    <button type='submit'
                                                                        style='background-color: #5d308e; color: white; font-weight: bold; border-radius: 4px;'>Update</button>
                                                                </form>
                                                            </td>

                                                        </tr>
                                                        <tr>
                                                            <td><strong>Address:</td>
                                                            <td><?php echo $studentDetails['student_address'];
                                                                    ?>
                                                            </td>
                                                        </tr>

                                                        <tr>
                                                            <td><strong>Secondary Education ( O/L ):</strong></td>
                                                            <td>
                                                                <?php
                                                                    $documentFound = false;
                                                                    // to check if any document is found

                                                                    if (isset($studentDetails['documents_ol']) && !empty($studentDetails['documents_ol'])) {
                                                                        foreach ($studentDetails['documents_ol'] as $education) {
                                                                            if (isset($education['education_doc_path']) && !empty($education['education_doc_path'])) {
                                                                                $documentFound = true;
                                                                                // Found a document

                                                                                // Check if education_doc_status is set
                                                                                $docStatus = isset($education['education_doc_status']) ? $education['education_doc_status'] : 0;

                                                                                // Display the document link
                                                                    ?>
                                                                <a href="../<?php echo htmlspecialchars($education['education_doc_path']); ?>"
                                                                    target='_blank'>
                                                                    View Document
                                                                </a>
                                                                <!-- Display the badge after the document link -->
                                                                <span style='margin-left: 10px;'>
                                                                    <?php
                                                                                    switch ($docStatus) {
                                                                                        case 1:
                                                                                            echo "<span class='badge badge-info'>Not Verified</span>";
                                                                                            break;
                                                                                        case 2:
                                                                                            echo "<span class='badge badge-success'>Accepted</span>";
                                                                                            break;
                                                                                        case 3:
                                                                                            echo "<span class='badge badge-warning'>Rejected</span>";
                                                                                            break;
                                                                                    }
                                                                                    ?>
                                                                </span>
                                                                <br>
                                                                <?php
                                                                            }
                                                                        }
                                                                    }

                                                                    if (!$documentFound) {
                                                                        // No valid document URL found,
                                                                        echo "<span class='badge badge-danger'>Please Upload Document</span>";
                                                                    }
                                                                    ?>
                                                            </td>
                                                        </tr>

                                                        <tr>
                                                            <td><strong>Secondary Education ( A/L ):</strong>
                                                            </td>
                                                            <td>
                                                                <?php
                                                                    $documentFound = false;
                                                                    // to check if any document

                                                                    if (isset($studentDetails['documents_al']) && !empty($studentDetails['documents_al'])) {
                                                                        foreach ($studentDetails['documents_al'] as $education) {
                                                                            if (isset($education['education_doc_path']) && !empty($education['education_doc_path'])) {
                                                                                $documentFound = true;
                                                                                // Found a document

                                                                                // Check if education_doc_status is set, 
                                                                                $docStatus = isset($education['education_doc_status']) ?
                                                                                    $education['education_doc_status'] : 0;
                                                                    ?>
                                                                <a href="../<?php echo htmlspecialchars($education['education_doc_path']); ?>"
                                                                    target='_blank'>
                                                                    View Document
                                                                </a>
                                                                <!-- Display the badge  -->
                                                                <span style='margin-left: 10px;'>
                                                                    <?php
                                                                                    switch ($docStatus) {
                                                                                        case 1:
                                                                                            echo "<span class='badge badge-info'>Not Verified</span>";
                                                                                            break;
                                                                                        case 2:
                                                                                            echo "<span class='badge badge-success'>Accepted</span>";
                                                                                            break;
                                                                                        case 3:
                                                                                            echo "<span class='badge badge-warning'>Rejected</span>";
                                                                                            break;
                                                                                    }
                                                                                    ?>
                                                                </span>
                                                                <br>
                                                                <?php
                                                                            }
                                                                        }
                                                                    }

                                                                    if (!$documentFound) {
                                                                        // No valid document URL found,
                                                                        echo "<span class='badge badge-danger'>Please Upload Document</span>";
                                                                    }
                                                                    ?>
                                                            </td>
                                                        </tr>

                                                        <tr>
                                                            <td><strong>Higher Education: <br>
                                                                    ( Certificate, Degree, Diploma,
                                                                    Master,Professional Qualification, PHD )
                                                                </strong>
                                                            </td>
                                                            <td>
                                                                <?php
                                                                    // to check if a document was found
                                                                    $documentFound = false;

                                                                    // Check if 'documents' is not empty
                                                                    if (isset($studentDetails['documents']) && !empty($studentDetails['documents'])) {
                                                                        // Iterate through the documents
                                                                        foreach ($studentDetails['documents'] as $education) {
                                                                            // Check if the document path is not empty
                                                                            if (isset($education['education_doc_path']) && !empty($education['education_doc_path'])) {
                                                                                $documentFound = true;
                                                                                // Found a document with a valid URL

                                                                                // Check if education_doc_status is set
                                                                                $docStatus = isset($education['education_doc_status']) ?
                                                                                    $education['education_doc_status'] : 0;
                                                                    ?>
                                                                <a href="../<?php echo htmlspecialchars($education['education_doc_path']); ?>"
                                                                    target='_blank'>
                                                                    View Document
                                                                </a>
                                                                <!-- Display the badge -->
                                                                <span style='margin-left: 10px;'>
                                                                    <?php
                                                                                    switch ($docStatus) {
                                                                                        case 1:
                                                                                            echo "<span class='badge badge-info'>Not Verified</span>";
                                                                                            break;
                                                                                        case 2:
                                                                                            echo "<span class='badge badge-success'>Accepted</span>";
                                                                                            break;
                                                                                        case 3:
                                                                                            echo "<span class='badge badge-warning'>Rejected</span>";
                                                                                            break;
                                                                                    }
                                                                                    ?>
                                                                </span>
                                                                <br>
                                                                <?php
                                                                            }
                                                                        }
                                                                    }

                                                                    if (!$documentFound) {
                                                                        // No valid document URL found, 
                                                                        echo "<span class='badge badge-danger'>Please Upload Document</span>";
                                                                    }
                                                                    ?>
                                                            </td>
                                                        </tr>

                                                        <tr>
                                                            <td><strong>Other Documents:</strong></td>
                                                            <td>
                                                                <?php
                                                                    $documentFound = false;
                                                                    // to check if any document with a valid URL is found

                                                                    if (isset($studentDetails['documents_other']) && !empty($studentDetails['documents_other'])) {
                                                                        foreach ($studentDetails['documents_other'] as $education) {
                                                                            if (isset($education['education_doc_path']) && !empty($education['education_doc_path'])) {
                                                                                $documentFound = true;  // Found a document with a valid URL

                                                                                // Check if education_doc_status is set,
                                                                                $docStatus = isset($education['education_doc_status']) ?
                                                                                    $education['education_doc_status'] : 0;
                                                                    ?>
                                                                <a href="../<?php echo htmlspecialchars($education['education_doc_path']); ?>"
                                                                    target='_blank'>
                                                                    View Document
                                                                </a>
                                                                <!-- Display the badge  -->
                                                                <span style='margin-left: 10px;'>
                                                                    <?php
                                                                                    switch ($docStatus) {
                                                                                        case 1:
                                                                                            echo "<span class='badge badge-info'>Not Verified</span>";
                                                                                            break;
                                                                                        case 2:
                                                                                            echo "<span class='badge badge-success'>Accepted</span>";
                                                                                            break;
                                                                                        case 3:
                                                                                            echo "<span class='badge badge-warning'>Rejected</span>";
                                                                                            break;
                                                                                    }
                                                                                    ?>
                                                                </span>
                                                                <br>
                                                                <?php
                                                                            }
                                                                        }
                                                                    }

                                                                    if (!$documentFound) {
                                                                        echo "<span class='badge badge-danger'>Please Upload Document</span>";
                                                                    }
                                                                    ?>
                                                            </td>
                                                        </tr>
                                                        <?php }
                                                        ?>

                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>

                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <?php include('./details.php');
                    ?>

</html>

</div>

<!-- footer start-->
<?php include('../includes/footers/footer.php');
?>
<!-- footer end-->
</div>
</div>

<!-- latest jquery-->
<script src='../assets/js/jquery-3.3.1.min.js'></script>

<!-- Bootstrap js-->
<script src='../assets/js/bootstrap.bundle.min.js'></script>

<!-- feather icon js-->
<script src='../assets/js/icons/feather-icon/feather.min.js'></script>
<script src='../assets/js/icons/feather-icon/feather-icon.js'></script>

<!-- Sidebar jquery-->
<script src='../assets/js/sidebar-menu.js'></script>
<script src='../assets/js/slick.js'></script>

<!-- lazyload js-->
<script src='../assets/js/lazysizes.min.js'></script>

<!--right sidebar js-->
<script src='../assets/js/chat-menu.js'></script>

<!--script admin-->
<script src='../assets/js/admin-script.js'></script>

<!-- Sweetalert2 js-->
<script src='../assets/custom-assets/lib/sweetalert2/sweetalert2.all.min.js'>
</script>

<!-- Moment js-->
<script src='../assets/custom-assets/lib/momentjs/moment.min.js'></script>

<!-- JDataTable js -->
<!-- <script src = '../assets/lib/DataTables/datatables.min.js'></script> -->
<script src='https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js'>
</script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js'>
</script>
<script
    src='https://cdn.datatables.net/v/dt/jszip-3.10.1/dt-1.13.6/af-2.6.0/b-2.4.2/b-colvis-2.4.2/b-html5-2.4.2/b-print-2.4.2/cr-1.7.0/date-1.5.1/fc-4.3.0/fh-3.4.0/kt-2.10.0/r-2.5.0/rg-1.4.1/rr-1.4.1/sc-2.2.0/sb-1.6.0/sp-2.2.0/sl-1.7.0/sr-1.3.0/datatables.min.js'>
</script>

<!-- dashbaord.js -->
<!-- <script src = 'assets/custom-assets/js/dashboard.js'></script> -->

</body>

</html>