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

$fac_roll = $val->ValidateString($_REQUEST['roll']);
?>
<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">Faculty Semester Feedback</h5>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-bordered align-middle">
                            <thead>
                                <tr>
                                    <th>&nbsp;</th>
                                    <th>Code</th>
                                    <th>Course Title</th>
                                    <th>Instructor</th>
                                    <th>Res</th>
                                    <th>Abs<th>
                                    <th>Score</th>
                                </tr>
                            </thead>

                            <?php
                            $qsem = "select distinct a.b1_sem, b.sem_name from isr_answers_gen4_tbl a, isr_iiser_sem_tbl b where a.fac_code = '$fac_roll' and a.b1_sem =b.sem_num  order by b1_sem";
                            $ObjDB->sproc_name = $qsem;
                            $res_qsem = $ObjDB->SelectQuery();
                            while ($rowsem = mysqli_fetch_array($res_qsem)) {

                                $for_sem = $rowsem['b1_sem'];
                                $sem_name = $rowsem['sem_name'];

                                $sub_sr = 1;
                                $semb1 = $for_sem;
                                $query1 = "SELECT concat(sub_code,'*',fac_code) as fc, count(*) as ccc, AVG(score) as avgr FROM isr_answers_gen4_tbl where b1_sem = '$semb1' and fac_code = '$fac_roll' and abstain = '' and sub_code <> '' group by  fc";
                                $ObjDB->sproc_name = $query1;
                                $res_query1 = $ObjDB->SelectQuery();
                                $num_rows = mysqli_num_rows($res_query1);
                                $total_rows = $num_rows;
                                if ($num_rows > 0) {
                                    while ($row1 = mysqli_fetch_array($res_query1)) {
                                        $fc = $row1["fc"];
                                        $ccc = $row1["ccc"];
                                        $score = round($row1['avgr'], 2);
                                        $ffcc = explode("*", $fc);
                                        $sub_code = $ffcc[0];
                                        $fac_code = $ffcc[1];
                                        $dis = substr($sub_code, 0, 3);

                                        $query7 = "SELECT * FROM isr_answers_gen4_tbl where concat(sub_code,'*',fac_code) = '$fc'  and b1_sem = '$semb1' and abstain = 'Y'";
                                        $ObjDB->sproc_name = $query7;
                                        $res_query7 = $ObjDB->SelectQuery();
                                        $abstain = mysqli_num_rows($res_query7);

                                        /// ---------- Count students Registered  Start ------------
                                        $sub_regg = 0;

                                        $qbatch = $objadm->MasterSystemFlags();

                                        while ($rowb = mysqli_fetch_array($qbatch)) {
                                            $reg_file = 'reg_' . $rowb['flag_user'];
                                            $qreg = "SELECT count(*) as ccc FROM $reg_file where sub_code = '$sub_code' and sub_flag = 'Y' and b1_sem = '$semb1'";
                                            $ObjDB->sproc_name = $qreg;
                                            $res_qreg = $ObjDB->SelectQuery();
                                            $rowr = mysqli_fetch_array($res_qreg);
                                            $sub_regg += $rowr["ccc"];
                                        }
                                        /// ---------- Count students Registered  End ------------

                                        $sub_list = 'c' . $semb1;
                                        $query3 = "SELECT * FROM isr_curriculum_tbl where sub_code = '$sub_code' and sub_list = '$sub_list'";
                                        $ObjDB->sproc_name = $query3;
                                        $res_query3 = $ObjDB->SelectQuery();
                                        $row3 = mysqli_fetch_array($res_query3);
                                        $sub_title = $row3["sub_title"];

                                        $objadm->fac_roll = $fac_code;
                                        $query6 = $objadm->GetFacultyList();
                                        $row6 = mysqli_fetch_array($query6);
                                        $name = $row6["name"];

                                        echo "<tr>";
                                        echo "<td class=thisp>" . $sem_name;
                                        echo "<td class=thisp>" . $sub_code;
                                        echo "<td class=thisp>" . $sub_title;
//	echo "<td class=thisp>".$sub_regg;
                                        echo "<td class=thisp>" . $name;
                                        echo "<td class=thisp>" . $ccc;
                                        echo "<td class=thisp>" . $abstain;
//	echo "<td class=thisp>".$score ;
//	echo "<td class=thisp>".$av_atn[$sub_code] ;
                                        ?>
                                        <td>
                                            <FORM METHOD=POST ACTION="feedback-faculty-student.php">
                                                <INPUT TYPE="hidden" NAME="sub_code" value="<?php echo $sub_code; ?>">
                                                <INPUT TYPE="hidden" NAME="sub_title" value="<?php echo $sub_title; ?>">
                                                <INPUT TYPE="hidden" NAME="sub_regg" value="<?php echo $sub_regg; ?>">
                                                <INPUT TYPE="hidden" NAME="fac_code" value="<?php echo $fac_code; ?>">
                                                <INPUT TYPE="hidden" NAME="for_sem" value="<?php echo $for_sem; ?>">

                                                <INPUT TYPE="hidden" NAME="name" value="<?php echo $name; ?>">
                                                <INPUT TYPE="hidden" NAME="response" value="<?php echo $ccc; ?>">
                                                <INPUT TYPE="hidden" NAME="abstain" value="<?php echo $abstain; ?>">
                                                <INPUT TYPE="submit" name="submit" value="<?php echo $score; ?>">
                                            </FORM>


            <?php
            echo "</tr>";
            $sub_sr++;
        }
    }
}
?>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php
$pagemaincontent = ob_get_contents();
ob_clean();
$PAGENAME = 'feedback-faculty-view';
$HTMLTITLE = '';
$HTMLDESCRIPTION = '';
$HTMLKEYWORDS = '';
include("admin-master.php");
?>