<?php
include_once '../session/admin-session.php';
include_once '../classes/class_admin.php';
include_once '../classes/validation.php';
include_once '../classes/common.php';
include_once 'read-configration.php';
ob_start();

$log = new common();
$objadm = new class_admin();
$val = new validation();
$ObjDB = new class_db();

$i = 0;
$find = $val->ValidateString($_REQUEST["roll_no"]);
if ($_POST) {
    $query = "SELECT * FROM isr_stu_main_tbl where (roll like '%$find%' or name like '%$find%') order by batch, roll";
    $ObjDB->sproc_name = $query;
    $res_query = $ObjDB->SelectQuery();
    $num = mysqli_num_rows($res_query);

    $query2 = "SELECT * FROM isr_gsam_student_tbl where (student_roll like '%$find%' or student_name like '%$find%') order by student_roll";
    $ObjDB->sproc_name = $query2;
    $res_query2 = $ObjDB->SelectQuery();
    $num2 = mysqli_num_rows($res_query2);
}
?>
<div class="container-fluid">
    <div class="row">
        <div class="col-xl-12 col-xxl-12 col-sm-12">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title">Office Notes on Students</h5>
                </div>
                <div class="card-body">
                    <form action="" method="POST">
                        <div class="row">
                            <div class="col-lg-6">
                                <INPUT TYPE="text" minlength="5" required="" NAME="roll_no" class="form-control input-sm" placeholder="Roll Number or Name (5 - 8 characters only)"/>
                            </div>
                            <div class="col-lg-6">
                                <INPUT TYPE="submit" name="btn_search_roll" value="Submit" class="btn btn-danger"/>
                            </div>
                        </div>
                    </form>
                    <br/><br/>
                    <div class="table-responsive">
                        <table class="table table-bordered align-middle">
                            <?php
                            if ($_POST['btn_search_roll']) {

                                if ($num > 0) {
                                    while ($row = mysqli_fetch_array($res_query)) {
                                        $stu_roll = $row["roll"];
                                        $stu_name = $row["name"];
                                        $batch = $row["batch"];
                                        $qb = "SELECT * FROM isr_system_flags_tbl where flag_user = '$batch' and flag_active in ('Y', 'Z')";
                                        $ObjDB->sproc_name = $qb;
                                        $res_qb = $ObjDB->SelectQuery();
                                        if (mysqli_num_rows($res_qb) == 1) {
                                            $i++;
                                            ?>
                                            <tr>
                                                <td><?php echo $i; ?></td>
                                                <td>
                                                    <FORM METHOD="POST" ACTION="reports-stu-notes-save.php">
                                                        <INPUT TYPE="submit" name="stu_roll" value="<?php echo $stu_roll; ?>" class="btn btn-success">
                                                    </FORM>
                                                </td>
                                                <td><?php echo $stu_name; ?></td>
                                                <td><?php echo $batch; ?></td>
                                            </tr> 
                                            <?php
                                        }
                                    }
                                }


                                if ($num2 > 0) {
                                    while ($row2 = mysqli_fetch_array($res_query2)) {
                                        $stu_roll = $row2["student_roll"];
                                        $stu_name = $row2["student_name"];
                                        $batch = 'PhD';
                                        $i++;
                                        ?>
                                        <tr>
                                            <td><?php echo $i; ?></td>
                                            <td>
                                                <FORM METHOD="POST" ACTION="reports-stu-notes-save.php">
                                                    <INPUT TYPE="submit" name="stu_roll" value="<?php echo $stu_roll; ?>">
                                                </FORM>
                                            </td>
                                            <td><?php echo $stu_name; ?></td>
                                            <td><?php echo $batch; ?></td>
                                        </tr>
                                        <?php
                                    }
                                }
                            }
                            ?>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php
$pagemaincontent = ob_get_contents();
ob_clean();
$PAGENAME = 'reports-stu-notes';
$HTMLTITLE = '';
$HTMLDESCRIPTION = '';
$HTMLKEYWORDS = '';
include("admin-master.php");
?>