<?php
    error_reporting(E_ALL);
    ini_set('display_errors', 1);

    include('../../config/config.php');

    $abba_campus_id = $_POST['abba_campus_id'];
    
    $abba_display_result_class = $_POST['abba_display_result_class'];
    
    $abba_display_session = $_POST['abba_display_session'];
    
    $abba_result_display_term = $_POST['abba_result_display_term'];
    
    $abba_get_instituion_id = $_POST['abba_get_instituion_id'];
    
    $abba_result_type = $_POST['abba_result_type'];

    $usertype = $_POST['usertype'];
    
    $abba_comments_staff = $_POST['abba_comments_staff'];

    $abba_comments_usertype = $_POST['abba_comments_usertype'];

    $abba_sql_student = "SELECT gradingstructure.GradingStructureID,gradingstructure.RangeStart,gradingstructure.RangeEnd 
    FROM classordepartment 
    INNER JOIN gradingmethod ON classordepartment.GradingMethodID=gradingmethod.GradingMethodID
    INNER JOIN gradingstructure ON gradingmethod.GradingMethodID=gradingstructure.GradingMethodID
    WHERE CampusID=$abba_campus_id AND ClassOrDepartmentID='$abba_display_result_class'";
    $abba_result_student = mysqli_query($link, $abba_sql_student);
    $abba_row_student = mysqli_fetch_assoc($abba_result_student);
    $abba_row_cnt_student = mysqli_num_rows($abba_result_student);
    
    if($abba_row_cnt_student > 0)
    {
        
        echo '<div class="row g-4 mt-1">';
               
            do{
                
                $GradingStructureID = $abba_row_student['GradingStructureID'];
                
                $abba_sql_defaultcomment = "SELECT * 
                FROM defaultcomment 
                WHERE CampusID=$abba_campus_id AND PrincipalOrDeanOrHeadTeacherUserID='$abba_comments_staff' AND CommentType='$abba_comments_usertype'";
                $abba_result_defaultcomment = mysqli_query($link, $abba_sql_defaultcomment);
                $abba_row_defaultcomment = mysqli_fetch_assoc($abba_result_defaultcomment);
                $abba_row_cnt_defaultcomment = mysqli_num_rows($abba_result_defaultcomment);

                echo '<div class="row">
                    <div class="col-lg-3">
                        <div class="mb-3">
                            <label for="exampleFormControlInput1" class="form-label">Range Start:</label>
                            <input type="email" class="form-control" disabled id="exampleFormControlInput1" placeholder="80" value="'.$abba_row_student['RangeStart'].'">
                        </div>
                    </div>
                    <div class="col-lg-3">
                        <div class="mb-3">
                            <label for="exampleFormControlInput1" class="form-label">Range End:</label>
                            <input type="email" class="form-control" disabled id="exampleFormControlInput1" placeholder="89.99" value="'.$abba_row_student['RangeEnd'].'">
                        </div>
                    </div>
                    <div class="col-lg-6">
                        <div class="mb-3">
                            <label for="comment_text_field" class="form-label">Comment:</label>
                            <textarea class="form-control comment_text_field" id="comment_text_field" data-id="'.$GradingStructureID.'" data-camp="'.$abba_campus_id.'" data-staffid="'.$abba_comments_staff.'" data-usertype="'.$abba_comments_usertype.'" rows="2" placeholder="Good Job">'.$abba_row_defaultcomment['DefaultComment'].'</textarea>
                        </div>
                    </div>
                </div>
                <hr>';
                    
            }while($abba_row_student = mysqli_fetch_assoc($abba_result_student));

        echo '</div>';
    }
    else
    {
        echo '<div align="center" class="mt-2"><img src="../../assets/images/adminImg/err.png" style="width:15%;"/><p class="pt-2 fs-6 text-secondary">We couldn\'t find any record.</p></div>';
    }
        
?>