<?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();

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

$datetime = date("Y-m-d H:i:s");

if ($_POST['update_profile_btn']) {
    $search_string = $val->ValidateString($_POST['search_s']);
    $roll = $val->ValidateString($_POST['roll3']);
    $new_status = $val->ValidateString($_POST['new_status']);

    $query1 = "update isr_stu_data_more_tbl set status = '$new_status' where roll = '$roll'";
    $ObjDB->sproc_name = $query1;
    $ObjDB->ExecuteQuery();

    $query2 = "update isr_stu_main_tbl set stu_status = '$new_status' where roll = '$roll'";
    $ObjDB->sproc_name = $query2;
    $ObjDB->ExecuteQuery();

    $activity = "Status of " . $roll . " changed to " . $new_status;
    $query3 = "INSERT INTO isr_actions_tbl (roll, activity, datetime) VALUES('" . $admin_roll . "','" . $activity . "','" . $datetime . "')";
    $ObjDB->sproc_name = $query3;
    $ObjDB->ExecuteQuery();
}

if ($_POST['reg_search_btn']) {
    $search_string = $val->ValidateString($_REQUEST['roll_number']);
    $string_check = 'N';
    if (is_numeric($search_string) and strlen($search_string) == 8) {
        $string_check = 'Y';
        $objadm->roll_number = $search_string;
        $rowStudent = $objadm->GetStudentDetailsbyRollNumber();
    } elseif (ctype_alpha($search_string) and strlen($search_string) > 2) {
        $string_check = 'Y';
        $objadm->stu_details = $search_string;
        $rowStudent = $objadm->GetStudentDetailsbyOtherValue();
    } else {
        $msg = "Search again. $search_string is not correct.";
    }

    if ($string_check == "Y") {
        if (mysqli_num_rows($rowStudent) > 0) {
            $j = 1;
            while ($resV = mysqli_fetch_array($rowStudent)) {
                $roll = $resV['roll'];
                $name = $resV['name'];
                $sr = $resV['sr'];
                $status = $resV['stu_status'];
                if ($status == 'OK')
                    $display_status = "On Roll";
                if ($status == 'PhD')
                    $display_status = "Doing PhD";
                if ($status == 'Comp')
                    $display_status = "Completed";
                if ($status == 'COS')
                    $display_status = "COS Exit";
                if ($status == 'BS')
                    $display_status = "BS Exit";
                if ($status == 'MS')
                    $display_status = "MS Exit";
                if ($status == 'Dip')
                    $display_status = "Diploma Exit";
                if ($status == 'Dis')
                    $display_status = "Discontinued";
                $ref = ($sr * $sr) + 222;

                $table_view .= '<tr><td><a href="registration-edit-profile.php?roll2=' . $roll . '&ref2=' . $ref . '&son2=' . $search_string . '">' . $roll . '</a></td><td>' . $name . '</td><td>' . $resV['dob'] . '</td><td>' . $resV['gender'] . '</td><td>' . $resV['category'] . '</td><td>' . $display_status . '</td></tr>';
                $j = $j + 1;
            }
        } else {
            $table_view .= '<tr><td colspan="6">' . $msg . '</td></tr>';
        }
    } else {
        $table_view .= '<tr><td colspan="6">No Records Found!</td></tr>';
    }
}
?>
<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">Student Search By Roll Number Or, Student Name to Edit Student Details</h5>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-lg-2"></div>
                        <div class="col-lg-8">                        
                            <form action="" method="POST">
                                <div class="mb-3" style="padding-left: 0px;">
                                    Roll Number / Name
                                </div>
                                <div class="mb-9" style="padding-left: 0px;">
                                    <input type="text" name="roll_number" id="roll_number"  class="form-control" value="<?php echo $roll_number; ?>"/>
                                    <br/><i>Enter roll number or at least 3 characters of name.</i>
                                </div>
                                <input type="submit" class="btn btn-danger" style="background: #a9181b;
                                       border: #a9181b; text-align: center;" value="Submit" name="reg_search_btn"/>

                            </form>

                        </div>
                        <div class="col-lg-2"></div><br/><br/>
                    </div>
                    <?php if ($_POST) { ?>
                        <div class="row">
                            <br/>
                            <div class="table-responsive">
                                <br/>
                                <table class="table table-striped table-bordered table-condensed">
                                    <thead>
                                        <tr>
                                            <th align="center">Roll</th>
                                            <th align="left">Name</th>
                                            <th align="left">DoB</th>
                                            <th align="left">Gender</th>
                                            <th align="left">Category</th>
                                            <th align="left">Status</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php echo $table_view; ?>      
                                    </tbody>
                                </table>

                            </div>
                        </div>
                    <?php } ?>
                </div>
            </div>
        </div>
    </div>
</div>
<?php
$pagemaincontent = ob_get_contents();
ob_clean();
$PAGENAME = 'registration-edit-student';
$HTMLTITLE = '';
$HTMLDESCRIPTION = '';
$HTMLKEYWORDS = '';
include("admin-master.php");
?>