<?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["medium"])) {

    $section = $_REQUEST["section"];
    $medium = $_REQUEST["medium"];

    switch ($section) {
        case 'P':
            $maindb = 'medprim';
            $ctr = 0;
            $mctr = 1;
            $getmsub = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE `code` = '$medium' order by srno")or die(mysqli_error($conn));
            while ($msub = mysqli_fetch_array($getmsub)) {
                echo "<tr>";
                Echo "<td><i class='fa fa-close remove' ></i></td>";
                Echo "<td><input type='text' class='form-control form text-right srno' name='srno_$ctr'      value='$mctr' readonly></td>";
                Echo "<td>";
                echo "<input type='text' name='subject_$ctr' class='form-control form' value='$msub[subjname]'>";
                echo "<input type='hidden' name='subname_$ctr' class='subname' value='$msub[subjcode]'>";
                Echo "</td>";
                Echo "<td><input type='number' class='form-control form text-right first'   name='first_$ctr'  step='any'   value=''></td>";
                Echo "<td><input type='number' class='form-control form text-right second'   name='second_$ctr' step='any'  value=''></td>";
                Echo "<td><input type='number' class='form-control form text-right third'   name='third_$ctr' step='any'  value=''></td>";
                Echo "<td><input type='number' class='form-control form text-right fourth'   name='fourth_$ctr'  step='any' value=''></td>";
                
                echo "<input type='hidden' class='f1'      value='$msub[f1]'>";
                echo "<input type='hidden' class='f2'      value='$msub[f2]'>";
                echo "<input type='hidden' class='f3'      value='$msub[f3]'>";
                echo "<input type='hidden' class='f4'      value='$msub[f4]'>";
                echo "</tr>";
                $ctr++;
                $mctr++;
            }
            break;
        case 'S':
            $maindb = 'medseco';
            $ctr2 = 0;
            $mctr2 = 1;
            $getmsub = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE `code` = '$medium' ")or die(mysqli_error($conn));
            while ($msub = mysqli_fetch_array($getmsub)) {
                echo "<tr>";
                Echo "<td><i class='fa fa-close remove' ></i></td>";
                Echo "<td><input type='text' class='form-control form text-right srno2'    name='srno2_$ctr2'      value='$mctr2'></td>";
                Echo "<td>";
                echo "<input type='text' name='subject2_$ctr2' class=' form-control form' value='$msub[subjname]'>";
                echo "<input type='hidden' class='subname2' name='subname2_$ctr2' value='$msub[subjcode]'>";
                Echo "</td>";
                Echo "<td><input type='number' step='any' class='form-control form text-right fifth'   name='fifth_$ctr2'     value=''></td>";
                Echo "<td><input type='number' step='any' class='form-control form text-right sixth'   name='sixth_$ctr2'   value=''></td>";
                Echo "<td><input type='number' step='any' class='form-control form text-right seventh' name='seventh_$ctr2'   value=''></td>";
                Echo "<td><input type='number' step='any' class='form-control form text-right eight'   name='eight_$ctr2'   value=''></td>";
                Echo "<td><input type='number' step='any' class='form-control form text-right ninth'   name='ninth_$ctr2'   value=''></td>";
                Echo "<td><input type='number' step='any' class='form-control form text-right tenth'   name='tenth_$ctr2'   value=''></td>";
                echo "<input type='hidden' class='f5'      value='$msub[f5]'>";
                echo "<input type='hidden' class='f6'      value='$msub[f6]'>";
                echo "<input type='hidden' class='f7'      value='$msub[f7]'>";
                echo "<input type='hidden' class='f8'      value='$msub[f8]'>";
                echo "<input type='hidden' class='f9'      value='$msub[f9]'>";
                echo "<input type='hidden' class='f10'      value='$msub[f10]'>";
                Echo "</tr>";
                $ctr2++;
                $mctr2++;
            }
            break;
        case 'M':
            $maindb = 'medprel';
            $ctr3 = 0;
            $mctr3 = 0;
            $getmsub = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE `code` = '$medium' ")or die(mysqli_error($conn));
            while ($msub = mysqli_fetch_array($getmsub)) {
                echo "<tr>";
                Echo "<td><i class='fa fa-close remove'></i></td>";
                Echo "<td><input type='text' class='form-control form text-right srno3'    name='srno3_$ctr3'      value='$mctr3'></td>";
                Echo "<td>";
                echo "<input type='text' name='subject3_$ctr3' class=' form-control form' value='$msub[subjname]'>";
                echo "<input type='hidden' class='subname3' name='subname3_$ctr3' value='$msub[subjcode]'>";
                Echo "</td>";
                Echo "<td><input type='number' step='any' class='form-control form text-right pqrelm'    name='pqrelm_$ctr3'      value=''></td>";
                
                echo "</tr>";
                $ctr3++;
                $mctr3++;
            }
    }
}