<?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';
            $pctr = 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_$pctr'      value='$mctr' readonly></td>";
                Echo "<td>";
                echo "<input type='text' name='subject_$pctr' class='form-control form' value='$msub[subjname]'>";
                echo "<input type='hidden' name='subname_$pctr' class='subname' value='$msub[subjcode]'>";
                Echo "</td>";
                Echo "<td class='p1'><input type='text' class='form-control form text-right first' id='first_$pctr'  name='first_$pctr'  step='any' autocomplete='off'  value=''>
                    <input type='hidden' class='f1' value='$msub[f1]'>    
                    </td>";
                Echo "<td class='p2'><input type='text' class='form-control form text-right second' id='second_$pctr'  name='second_$pctr' step='any' autocomplete='off' value=''>
                    <input type='hidden' class='f2' value='$msub[f2]'>
                        </td>";
                Echo "<td class='p3'><input type='text' class='form-control form text-right third' id='third_$pctr'  name='third_$pctr' step='any' autocomplete='off' value=''>
                    <input type='hidden' class='f3' value='$msub[f3]'>
                        </td>";
                Echo "<td class='p4'><input type='text' class='form-control form text-right fourth' id='fourth_$pctr'  name='fourth_$pctr' autocomplete='off' step='any' value=''>
                     <input type='hidden' class='f4' value='$msub[f4]'>   
                     </td>";
//                echo "<input type='hidden' name='count' class='count' value='$pctr'>";
                echo "</tr>";
                
                   $pctr++;
                   $mctr++;
            }
            echo "<input type='hidden' name='count'  class='totrow' value='$pctr'>";
            
            break;
        case 'S':
            $maindb = 'medseco';
            $pctr2 = 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_$pctr2'      value='$mctr2' readonly></td>";
                Echo "<td>";
                echo "<input type='text' name='subject2_$pctr2' class=' form-control form' value='$msub[subjname]'>";
                echo "<input type='hidden' class='subname2' name='subname2_$pctr2' value='$msub[subjcode]'>";
                Echo "</td>";
                Echo "<td class='p5'><input type='text' step='any' class='form-control form text-right fifth' id='fifth_$pctr2'  name='fifth_$pctr2'  autocomplete='off'   value=''>
                        <input type='hidden' class='f5'      value='$msub[f5]'></td>";
                Echo "<td class='p6'><input type='text' step='any' class='form-control form text-right sixth' id='sixth_$pctr2'  name='sixth_$pctr2' autocomplete='off'  value=''>
                       <input type='hidden' class='f6'      value='$msub[f6]'>
                        </td>";
                Echo "<td class='p7'><input type='text' step='any' class='form-control form text-right seventh' id='seventh_$pctr2' name='seventh_$pctr2' autocomplete='off'  value=''>
                        <input type='hidden' class='f7'      value='$msub[f7]'>
                        </td>";
                Echo "<td class='p8'><input type='text' step='any' class='form-control form text-right eight' id='eight_$pctr2'  name='eight_$pctr2' autocomplete='off'  value=''>
                     <input type='hidden' class='f8'      value='$msub[f8]'>   
                     </td>";
                Echo "<td class='p9'><input type='text' step='any' class='form-control form text-right ninth' id='ninth_$pctr2'  name='ninth_$pctr2' autocomplete='off'  value=''>
                    <input type='hidden' class='f9'      value='$msub[f9]'>
                        </td>";
                Echo "<td class='p10'><input type='text' step='any' class='form-control form text-right tenth' id='tenth_$pctr2'  name='tenth_$pctr2' autocomplete='off'  value=''>
                    <input type='hidden' class='f10'      value='$msub[f10]'>
                        </td>";
//                echo "<input type='hidden' name='count2' class='count2' value='$pctr2'>";
                Echo "</tr>";
                $pctr2++;
                $mctr2++;
            }
            echo "<input type='hidden' name='count2'  class='totrow2' value='$pctr2'>";
            break;
        case 'M':
            $maindb = 'medprel';
            $pctr3 = 0;
            $mctr3 = 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 srno3'    name='srno3_$pctr3'      value='$mctr3' readonly></td>";
                Echo "<td>";
                echo "<input type='text' name='subject3_$pctr3' class=' form-control form' value='$msub[subjname]'>";
                echo "<input type='hidden' class='subname3' name='subname3_$pctr3' value='$msub[subjcode]'>";
                Echo "</td>";
                Echo "<td class='prel'><input type='text' step='any' class='form-control form text-right pqrelm' id='pqrelm_$pctr3'   name='pqrelm_$pctr3' autocomplete='off' value=''>
                        <input type='hidden' class='fprel'      value='$msub[fprel]'></td>";
//                echo "<input type='hidden' name='count3' class='count3' value='$pctr3'>";
                echo "</tr>";
                $pctr3++;
                $mctr3++;
            }
            echo "<input type='hidden' name='count3'  class='totrow3' value='$pctr3'>";
    }
}