<?php

require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include("includes/function.php");

$zdb = $_SESSION["zdbyear_$dbname"];
$ztit = $_SESSION["tit"];
$usertype = $_SESSION["usertype"];
$user = $_SESSION['username_' . $dbname];
$keyfld = "vouchno";

mysqli_select_db($conn, $zdb);

if (isset($_REQUEST["fexam"])) {
    $fexam = $_REQUEST["fexam"];
    $section = $_REQUEST["section"];
    $session = $_REQUEST["session"];


    echo "<table class='table table-bordered table-hover myTable' style='width: 50%;'>";
    echo "<tr class='' style='background-color: #6082BF;color: white;'>";
    echo "<td style='width: 8%;'><input type='checkbox' class='allchk' value='' >&nbsp; ALL S/US</td>";
    echo "<td style='width: 13%;'><b>Code</b></td>";
    echo "<td style='width: 30%;'><b>Name</b></td>";

    $getcustcode = mysqli_query($conn, "select  custcode from demdmain where  examcode = '$fexam' and 
                                section = '$section' AND session = '$session' 
                                group by custcode order by custcode, vouchno desc") or die(mysqli_error($conn));
    $count = mysqli_num_rows($getcustcode);
    $ctr = 0;

    while ($fcustcode = mysqli_fetch_array($getcustcode)) {
        $custcode = $fcustcode['custcode'];
        $srchresult = mysqli_query($conn, "SELECT accode,name FROM `accmast` WHERE `custcode` = '$custcode' AND `grpcode`='010' ")or die(mysqli_error($conn));


        echo "</tr>";
        $row2 = mysqli_fetch_array($srchresult);
        $modcode = $custcode;
        $modname = $row2['name'];
        echo "<tr>";
        echo "<td>";
        echo "<input type='checkbox' class='mcheck' name='check_$ctr' value='1'>";
        echo "</td>";
        echo "<td><b>$modcode</b>
                 <input type='hidden' name='scust_$ctr' class='scust' value='$modcode' >
                 <input type='hidden' name='accode_$ctr' value='$row2[accode]' class='accode'>
                 </td>";
        echo "<td><b>$modname<input type='hidden'  class='sname' name='sname_$ctr' value='$modname' readonly></b>
                 </td>";
        echo "<input type='hidden' name='saccode_$ctr' class='saccode' value='' >";
        echo "<input type='hidden' name='ncust_$ctr' class='ncust' value=''>";
        echo "</tr>";
        echo "";
        $ctr++;
    }
    echo "<input type='hidden'  class='scount' value='$count'>";
    echo "</table>";
}