<?php 

function student_profile_cb() {
    $session = Session::getInstance();
    global $app;
    $user_meta = $app->user_meta;
    global $post_meta;
    $user = new user;
    if(isset($_GET['id'])) {
        $id = $_GET['id'];
        if($user_meta['role'] == 'student' && $user_meta['id'] == $id) {
            do_action('student_profile', ['id' => $id]);
            return;
        }
        if($user_meta['role'] == 'student' && $user_meta['id'] != $id) {
            return_method();
        }
        if($user_meta['role'] == 'teacher') {
            do_action('student_profile', ['id' => $id]);
            return;
        }
    } else {
        if($user_meta['role'] == 'student') {
            do_action('student_profile', ['id' => $session->id]);
            return;
        } else {
            return_method();
        }
    }
    $umeta = $user->get_user_meta($id);
    $classes = get_select_options_from_post(['type' => 'class'], 'class_name');
    $categories = get_select_options_from_post(['type' => 'category'], 'category_name');
    $token = new_token();
    $all_terms = get_select_options_from_post_q(['type' => 'academic_term'], 'term_name');
    ?>
    <style type="text/css">
        .toggle-btn {
            display: block;
            color: #44a1ef;
            font-style: italic;
            border-bottom: 1px dotted;
            font-size: 12px;
        }
    </style>
<div class="col-lg-12">
    <div class="card">
        
            <div class="card-header">
                <h4><?php echo get_fullname($umeta) ?>'s Profile</h4>
            </div>
            <div class="card-body">
                <div class="custom-tab">
                    <nav>
                        <div class="nav nav-tabs" id="nav-tab" role="tablist">
                            <a class="nav-item nav-link active show" id="custom-nav-home-tab" data-toggle="tab" href="#basic-information" role="tab" aria-controls="custom-nav-home" aria-selected="true">Basic Information</a>
                            <a class="nav-item nav-link" id="custom-nav-profile-tab" data-toggle="tab" href="#parents-guardian" role="tab" aria-controls="custom-nav-profile" aria-selected="false">Parents/Guardian</a>
                            <a class="nav-item nav-link" id="custom-nav-contact-tab" data-toggle="tab" href="#psychometrics" role="tab" aria-controls="custom-nav-contact" aria-selected="false">Psychometrics</a>
                            <?php do_action('_after_student_profile_more_info_link'); ?>
                        </div>
                    </nav>
                    <div class="tab-content pl-3 pt-2" id="nav-tabContent">
                        <div class="tab-pane fade active show" id="basic-information" role="tabpanel" aria-labelledby="custom-nav-home-tab">
                            <div class="offset-md-2 col-md-8">
                                <div class="card">
                                    <div class="card-body">
                                        <form method="post" action="contents/plugins/eedu_portal/ajax.php" id="basic-info-form" enctype="multipart/form-data">
                                            <input type="hidden" name="id" id="stud-id-bif" value="<?php echo $umeta['id'] ?>">
                                <div class="row">
                                    <div class="col-sm-4">
                                        <?php do_action('croppie_api', ['width' => 200, 'height' => 200, 'boundaryheight' => 210, 'boundarywidth' => 210, 'url' => get_user_image($umeta), 'image-name' => 'profile_picture']); ?>
                                    </div>
                                    <div class="col-sm-8">
                                        <?php do_action("profile_state", $umeta);; ?>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-sm-6">
                                        <?php input(['label' => 'Surname', 'id' => 'surname', 'required' => 'required', 'value' => $umeta['surname']]); ?>
                                    </div>
                                    <div class="col-sm-6">
                                        <?php input(['label' => 'Other Names', 'id' => 'other_names', 'required' => 'required', 'value' => $umeta['other_names']]); ?>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-sm-6">
                                        <?php input(['label' => 'Date of Birth', 'id' => 'dob', 'value' => $umeta['dob']]); ?>
                                    </div>
                                    <div class="col-sm-6">
                                        <?php select(['label' => 'Gender', 'id' => 'gender', 'data-noclear' => true], ['Male' => 'Male', 'Female' => 'Female'], display_gender($umeta['gender'])); ?>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-sm-6">
                                        <?php select(['label' => 'Class', 'id' => 'class', 'required' => 'required', 'data-noclear' => true], $classes, $umeta['class']); ?>
                                    </div>
                                    <div class="col-sm-6">
                                        <?php select(['label' => 'Category', 'id' => 'category', 'required' => 'required', 'data-noclear' => true], $categories, $umeta['category']); ?>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-sm-6">
                                        <?php input(['label' => "Student's Phone Number", 'id' => 'phone', 'value' => $umeta['phone'], 'type' => 'phone']); ?>
                                    </div>
                                    <div class="col-sm-6">
                                        <?php input(['label' => 'State Reg. Number', 'id' => 'state_reg_number', 'value' => $umeta['state_reg_number']]); ?>
                                    </div>
                                </div>
                                <div class="d-block mt-3 mb-3">
                                    <a href="#more-information" data-toggle="collapse" class="toggle-btn">More Information</a>
                                    <div class="row collapse" id="more-information">
                                        <div class="col-md-12">
                                            <?php textarea(['label' => 'Residential Address', 'id' => 'address', 'value' => $umeta['address']]); ?>
                                            <div class="row">
                                                <div class="col-sm-6">
                                                    <?php input(['label' => 'State of Origin', 'id' => 'state', 'value' => $umeta['state']]); ?>
                                                </div>
                                                <div class="col-sm-6">
                                                    <?php input(['label' => 'LGA', 'id' => 'lga', 'value' => $umeta['lga']]); ?>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-sm-6">
                                                    <?php input(['label' => 'Genotype', 'id' => 'genotype', 'value' => $umeta['genotype']]); ?>
                                                </div>
                                                <div class="col-sm-6">
                                                    <?php input(['label' => 'Blood Group', 'id' => 'blood_group', 'value' => $umeta['blood_group']]); ?>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-sm-6">
                                                    <?php textarea(['label' => 'Physical Challenges', 'id' => 'physical_challenges', 'value' => $umeta['physical_challenges']]); ?>
                                                </div>
                                                <div class="col-sm-6">
                                                    <?php select(['label' => 'Term of Admission', 'id' => 'term_of_admission', 'data-form' => 'search-form', 'hint' => 'This will be used to determine if the student should pay registration fee or not'], $all_terms, $umeta['term_of_admission']); ?>
                                                </div>
                                            </div>
                                            <?php 
                                                
                                             ?>
                                        </div>
                                    </div>
                                </div>
                                <?php
                                do_action("eedu_student_profile_more", $umeta);
                                submit_btn("edit_student_profile", "Submit", "submit-sif");
                             ?>
                         </form></div></div></div>
                        </div>
                        <div class="tab-pane fade" id="parents-guardian" role="tabpanel" aria-labelledby="custom-nav-profile-tab">
                            <div class="offset-md-2 col-md-8">
                                <div class="card">
                                    <div class="card-body">
                                        <form method="post" action="contents/plugins/eedu_portal/ajax.php" id="parents-info-form" enctype="multipart/form-data">
                                            <input type="hidden" name="id" id="stud-id-pif" value="<?php echo $umeta['id'] ?>">
                                            <?php 
                                                label('Nominee 1', 'h4');
                                                input(['label' => 'Fullname', 'id' => 'n1_fullname', 'value' => $umeta['n1_fullname']]);
                                                input(['label' => 'Relationship', 'id' => 'n1_relationship', 'value' => $umeta['n1_relationship']]);
                                             ?>
                                            <div class="row">
                                                <div class="col-sm-6">
                                                    <?php input(['label' => 'Phone', 'id' => 'n1_phone', 'value' => $umeta['n1_phone']]); ?>
                                                </div>
                                                <div class="col-sm-6">
                                                    <?php input(['label' => 'Email', 'id' => 'n1_email', 'value' => $umeta['n1_email']]); ?>
                                                </div>
                                            </div>
                                            <div class="d-block mt-3 mb-3">
                                                <a href="#more-nominees" data-toggle="collapse" class="toggle-btn">More Nominees</a>
                                                <div class="row collapse" id="more-nominees">
                                                    <div class="col-md-12">
                                                        <?php 
                                                            label('Nominee 2', 'h4');
                                                            input(['label' => 'Fullname', 'id' => 'n2_fullname', 'value' => $umeta['n2_fullname']]);
                                                            input(['label' => 'Relationship', 'id' => 'n2_relationship', 'value' => $umeta['n2_relationship']]);
                                                         ?>
                                                        <div class="row">
                                                            <div class="col-sm-6">
                                                                <?php input(['label' => 'Phone', 'id' => 'n2_phone', 'value' => $umeta['n2_phone']]); ?>
                                                            </div>
                                                            <div class="col-sm-6">
                                                                <?php input(['label' => 'Email', 'id' => 'n2_email', 'value' => $umeta['n2_email']]); ?>
                                                            </div>
                                                        </div><hr>
                                                        <?php 
                                                            label('Nominee 3', 'h4');
                                                            input(['label' => 'Fullname', 'id' => 'n3_fullname', 'value' => $umeta['n3_fullname']]);
                                                            input(['label' => 'Relationship', 'id' => 'n3_relationship', 'value' => $umeta['n3_relationship']]);
                                                         ?>
                                                        <div class="row">
                                                            <div class="col-sm-6">
                                                                <?php input(['label' => 'Phone', 'id' => 'n3_phone', 'value' => $umeta['n3_phone']]); ?>
                                                            </div>
                                                            <div class="col-sm-6">
                                                                <?php input(['label' => 'Email', 'id' => 'n3_email', 'value' => $umeta['n3_email']]); ?>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                            <?php
                                submit_btn("edit_student_profile", "Submit", "submit-pif");
                            ?>
                        </form></div></div></div>
                        </div>
                        <div class="tab-pane fade" id="psychometrics" role="tabpanel" aria-labelledby="custom-nav-profile-tab">
                            <div class="offset-md-2 col-md-8">
                                <div class="card">
                                    <div class="card-body">
                            <?php do_action('get_psychometrics', ['student_id' => $umeta['id']]); ?>
                        </div></div></div>
                        </div>

                        <?php do_action('_after_student_profile_more_info', ['student' => $umeta]); ?>
                    </div>
                    
                </div>

            </div>
            <!-- </div> -->
        


        <div class="modal" id="cropImagePop" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel">Edit Photo</h4>
                    </div>
                    <div class="modal-body">
                        <div id="upload-demo" class="center-block"></div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        <button type="button" id="cropImageBtn" class="btn btn-primary">Crop</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php
    add_page_javascript('app/assets/js/page-scripts/submit.js');
    add_page_javascript('contents/plugins/eedu_portal/js/update-students-in-class.js');
    add_page_javascript('app/assets/js/page-scripts/koweb.js');
}
