<?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();
$log = new common();
$objadm = new class_admin();
$val = new validation();

if(!empty($_REQUEST['Delsubr'])){
    $Delsubr = $val->ValidateString($_REQUEST['Delsubr']);
    $query4 = "delete from isr_feedback_block_tbl where reg_sr = '$Delsubr'";
    $ObjDB->sproc_name = $query4;
    $ObjDB->ExecuteQuery();
    
    header("Location: control-feedback-block.php");
}

if ($_POST['blk']) {
    $stu_roll = $val->ValidateString($_REQUEST["roll_no"]);
    $sub_code = $val->ValidateString($_REQUEST["sub_code"]);

    $objadm->roll_number = $stu_roll;
    $RollNumberArr = $objadm->GetStudentDetailsbyRollNumber();
    $num = mysqli_num_rows($RollNumberArr);
    $row = mysqli_fetch_array($RollNumberArr);

    $name = $row['name'];
    $batch = $row['batch'];
    $reg_file = "isr_reg_" . $batch . "_tbl";

    $query2 = "SELECT * FROM $reg_file where stu_roll = '$stu_roll' and sub_code = '$sub_code'";
    $ObjDB->sproc_name = $query2;
    $res_Query2 = $ObjDB->SelectQuery();

    $num_rows = mysqli_num_rows($res_Query2);
    if ($num_rows > 0) {
        $query3 = "SELECT * FROM isr_feedback_block_tbl where stu_roll = '$stu_roll' and sub_code = '$sub_code'";
        $ObjDB->sproc_name = $query3;
        $res_query3 = $ObjDB->SelectQuery();

        $num_rows3 = mysqli_num_rows($res_query3);
        if ($num_rows3 == 0) {
            $query4 = "INSERT INTO isr_feedback_block_tbl (stu_roll, sub_code) VALUES ('$stu_roll','$sub_code')";
            $ObjDB->sproc_name = $query4;
            $res_query4 = $ObjDB->SelectQuery();

            $message .= "$name - $stu_roll has been blocked for $sub_code";
        } else {
            $message .= "$name - $stu_roll is already blocked for $sub_code";
        }
    } else {
        $message .= "$name - $stu_roll has not opted $sub_code";
    }
}

$query_stu = "SELECT * from isr_stu_main_tbl where batch in ('b4', 'b5', 'b6', 'b7') order by roll";
$ObjDB->sproc_name = $query_stu;
$res_query_stu = $ObjDB->SelectQuery();

$query_sub = "SELECT * from isr_sub_available_tbl where sem in ('2', '4', '6', '8') order by sub_code";
$ObjDB->sproc_name = $query_sub;
$res_query_sub = $ObjDB->SelectQuery();
?>
<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">Block Feedback</h5>
                </div>
                <div class="card-body">
                    <div class="row"><div class="col-lg-12"><?php echo $message; ?></div></div>
                    <div class="row">
                        <FORM  METHOD="POST" ACTION="">
                            <TABLE class="table table-bordered align-middle">

                                <tr>
                                    <td><label>&nbsp;&nbsp;&nbsp;&nbsp;Roll No</label></td>
                                    <td>
                                        <SELECT NAME="roll_no" class="form-control" required="">
                                            <OPTION VALUE="" SELECTED>- Select -
                                                <?php
                                                while ($row = mysqli_fetch_array($res_query_stu)) {
                                                    $stu_roll = $row["roll"];
                                                    echo "<OPTION VALUE=$stu_roll>$stu_roll";
                                                }
                                                ?>
                                        </SELECT>
                                    </td>
                                    <td><label>&nbsp;&nbsp;&nbsp;&nbsp;Sub Code</label></td>
                                    <td>
                                        <SELECT NAME="sub_code" class="form-control" required="">
                                            <OPTION VALUE="" SELECTED>- Select -
                                                <?php
                                                while ($row = mysqli_fetch_array($res_query_sub)) {
                                                    $sub_code = $row["sub_code"];
                                                    echo "<OPTION VALUE=$sub_code>$sub_code";
                                                }
                                                ?>
                                        </SELECT>
                                    </td>
                                </tr>
                                <tr><td colspan="4" align=center>
                                        <INPUT TYPE="submit" name="blk" value="Block" class="btn btn-primary">
                                    </td></tr>
                            </TABLE>
                        </FORM>
                    </div>


                    <div class="table-responsive">
                        <TABLE class="table table-bordered align-middle">
                            <tr>
                                <th align="center">Roll</th>
                                <th align="left">Student Name</th>
                                <th align="center">Subject</th>
                                <th align="center">&nbsp;</th>
                            </tr>
                            <?php
                            
                            $block_list="SELECT a.stu_roll, a.sub_code, a.reg_sr, b.name from isr_feedback_block_tbl a, isr_stu_main_tbl b where a.stu_roll = b.roll order by a.stu_roll";
                            $ObjDB->sproc_name = $block_list;
                            $res_block_list = $ObjDB->SelectQuery();
                            while ($row_block = mysqli_fetch_array($res_block_list)) {
	$subr = $row_block['reg_sr'];
	echo "<tr>";
	echo "<td>".$row_block['stu_roll'];
	echo "<td>".$row_block['name'];
	echo "<td>".$row_block['sub_code'];
	echo "<td>"."<A HREF='?Delsubr=".$subr."'>Delete</A>";

	echo "</tr>";
}
                            
                            ?>
                            
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php
$pagemaincontent = ob_get_contents();
ob_clean();
$PAGENAME = 'control-feedback-block';
$HTMLTITLE = '';
$HTMLDESCRIPTION = '';
$HTMLKEYWORDS = '';
include("admin-master.php");
?>