<?php
//header('refresh: 2');
include('connection.php');
$table = 0;
if (isset($_POST['i_submit'])) {
    $errors = [];
    $u = strtoupper($_POST['u']);
    $ub = strtoupper($_POST['ub']);

    $select = "SELECT * FROM students WHERE fn='$u' AND cl='$ub' AND class_status='in-active'";
    $sql = mysqli_query($conn, $select);
    //$fetch = mysqli_fetch_object($sql);

    $table = 1;
}

if (isset($_POST['b_submit'])) {
    $errors = [];
    $class = strtoupper($_POST['b_c']);
    // $year = strtoupper($_POST['b_y']);

    $select = "SELECT * FROM students WHERE cl='$class' AND class_status='in-active'";

    $sql = mysqli_query($conn, $select);

    $table = 2;
}
?>



<?php include 'includes/header.php'; ?>

<?php include 'includes/sidebar.php'; ?>
<?php include 'includes/topbar.php'; ?>


<!-- page content -->
<div class="right_col" role="main">
    <div class="">
        <div class="clearfix"></div>

        <div class="row">
            <div class="col-md-6 col-sm-6">
                <div class="x_panel">
                    <div class="x_title">
                        <h2>Search Last Years Student Information</h2>
                        <ul class="nav navbar-right panel_toolbox">
                            <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                            </li>
                        </ul>
                        <div class="clearfix"></div>
                    </div>
                    <div class="x_content">
                        <form class="" action="" method="post" novalidate>
                            <h4 style="color:black;">Search Individual Student</h4>
                            <hr>
                            <div class="field item form-group">

                                <div class="col-md-5 col-sm-6">
                                    <label class="col-form-label col-md-3 col-sm-3">Student Name <span class="required">*</span></label>
                                    <input class="form-control" type="text" class='number' name="u" data-validate-minmax="10,100" required='required' autocomplete="off">
                                </div>
                                <div class="col-md-3 col-sm-6">
                                    <label class="col-form-label col-md-3 col-sm-3">Class <span class="required">*</span></label>

                                    <select class="form-control" name="ub">
                                        <option>---Select---</option>
                                        <option value="Nursery">Nursery</option>
                                        <option value="STD I">STD I</option>
                                        <option value="STD II">STD II</option>
                                        <option value="STD III">STD III</option>
                                        <option value="STD IV">STD IV</option>
                                        <option value="STD V">STD V</option>
                                        <option value="STD VI">STD VI</option>
                                        <option value="STD VII">STD VII</option>
                                    </select>
                                </div>

                                <div class="col-md-4 col-sm-6" style="margin-top: 5.5vh;">
                                    <button type='submit' name="i_submit" class="btn btn-primary">Submit</button>
                                    <button type='reset' class="btn btn-success">Reset</button>
                                </div>
                            </div>

                            <hr>
                        </form>
                    </div>
                </div>
            </div>


            <div class="col-md-6 col-sm-6">
                <div class="x_panel">
                    <div class="x_title">
                        <h2>Search Last Years Student Information</h2>
                        <ul class="nav navbar-right panel_toolbox">
                            <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                            </li>
                        </ul>
                        <div class="clearfix"></div>
                    </div>
                    <div class="x_content">
                        <form class="" action="" method="post" novalidate>
                            <h4 style="color:black;">Search Based on Class</h4>
                            <hr>
                            <div class="field item form-group">
                                <div class="col-md-4 col-sm-6">
                                    <label class="col-form-label col-md-3 col-sm-3">Class <span class="required">*</span></label>

                                    <select class="form-control" name="b_c">
                                        <option>---Select---</option>
                                        <option value="Nursery">Nursery</option>
                                        <option value="STD I">STD I</option>
                                        <option value="STD II">STD II</option>
                                        <option value="STD III">STD III</option>
                                        <option value="STD IV">STD IV</option>
                                        <option value="STD V">STD V</option>
                                        <option value="STD VI">STD VI</option>
                                        <option value="STD VII">STD VII</option>
                                    </select>
                                </div>
<!-- 
                                <div class="col-md-4 col-sm-6">
                                    <label class="col-form-label col-md-3 col-sm-3">Year <br><span class="required">*</span></label>
                                    <input class="form-control" type="text" class='number' name="b_y" placeholder="format : 2020 or 2019" required='required' autocomplete="off">
                                </div> -->

                                <div class="col-md-4 col-sm-6" style="margin-top: 5.5vh;">
                                    <button type='submit' name="b_submit" class="btn btn-primary">Submit</button>
                                    <button type='reset' class="btn btn-success">Reset</button>
                                </div>
                            </div>


                            <hr>
                        </form>
                    </div>
                </div>
            </div>

        </div>


        <div class="row">
            <div class="col-md-12 col-sm-12">
                <div class="x_panel">
                    <div class="x_title">
                        <h2>Search Last Years Student Information</h2>
                        <ul class="nav navbar-right panel_toolbox">
                            <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                            </li>
                        </ul>
                        <div class="clearfix"></div>
                    </div>
                    <div class="x_content">
                        <?php if ($table == 1 || $table == 2) : ?>
                            <table id="datatable-buttons" class="table table-striped table-bordered" style="width:100%">
                                <thead>
                                    <tr>
                                        <th>Full Name</th>
                                        <th>Gender</th>
                                        <th>Class</th>
                                        <th>Live Place</th>
                                        <th>Status</th>
                                        <th>Date</th>
                                        <th>Amount Paid</th>
                                        <th>Debt</th>
                                        <th>Update</th>
                                        <th>Print</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                    $k = 1;
                                    $total = 0;
                                    while ($fetch = mysqli_fetch_object($sql)) {
                                        $f = $fetch->ud;
                                        $e = $fetch->jan;
                                        $d = $fetch->apr;
                                        $c = $fetch->jul;
                                        $b = $fetch->sep;
                                        $a = $fetch->others;
                                        $amount = $a + $b + $c + $d + $e + $f;

                                        if ($fetch->lp == 'BOARDING') {
                                            $amount_debt = 1600000 - $amount;
                                        } else {
                                            $amount_debt = 1200000 - $amount;
                                        }


                                    ?>
                                        <tr>
                                            <td><?php echo $fetch->fn; ?></td>
                                            <td><?php echo $fetch->gd; ?></td>
                                            <td><?php echo $fetch->cl; ?></td>
                                            <td><?php echo $fetch->lp; ?></td>
                                            <td><?php echo $fetch->class_status; ?></td>
                                            <td><?php echo $fetch->dt; ?></td>
                                            <td><?php echo number_format($amount) . " /="; ?></td>
                                            <td><?php echo number_format($amount_debt) . " /="; ?></td>
                                            <td style="width: 5%;"><a href="update_students.php?key=<?php echo $fetch->id;  ?>"><i style="color: red; font-size: 18px; margin-left: 20px; " class="fa fa-edit"></i></a></td>

                                            <td style="color: red;"><i style="color: red;" class="fa fa-file-pdf-o"></i> <a style="font-weight:bold; color: blue;" href="reports/pdf.php?p=<?php echo $fetch->id; ?>">Print Student Details</a></td>

                                        </tr>
                                    <?php

                                        $total += $amount;
                                        $k++;
                                    }
                                    ?>
                                </tbody>
                            </table>
                        <?php endif ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- /page content -->


<?php include 'includes/footer.php'; ?>