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

// ------------------------------------------------ LABELS SET ON ENVELOP B5 IN CTRL+P ----------------------------------------------

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$maindb = 'demdmain';
$trandb = 'demdtran';
$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);
$zroot = $_SESSION["zdir"];

if (isset($_POST["view"])) {
    $formname = ' Labels - Subject';
    $frmvouch = $_POST["fvouch"];
    $tovouch  = $_POST["tvouch"];
    $section  = $_POST["section"];
    $school   = $_POST["name"];
    $medium   = $_POST["medmcode"];
    $session  = $_POST["session"];
    $subject  = $_POST["subject"];
    $std      = $_POST["std"];
    $exam     = $_POST["exam"];

    $sectcond = "";
    $schlcond = "";
    $medmcond = "";
    $sesscond = "";
    $subjcond = "";
    $examcond = "";
    $rangecond = "";

    if (!empty($section)) {
        $sectcond = " AND a.`section` = '$section' ";
    }

    if (!empty($school)) {
        $schlcond = " AND a.`accode` = '$school' ";
    }

    if (!empty($medium)) {
        $medmcond = " AND a.`medmcode` = '$medium' ";
    }

    if (!empty($session)) {
        $sesscond = " AND a.`session` = '$session' ";
    }

    if (!empty($subject)) {
        $subjcond = " AND b.`subjcode` = '$subject' ";
    }


    if (!empty($exam)) {
        $examcond = " AND a.`examcode` = '$exam' ";
    }

    if (!empty($frmvouch)) {
        $rangecond = " and a.`vouchno` between $frmvouch and $tovouch ";
    }

     $gmain = mysqli_query($conn, "SELECT a.*, b.subjcode, b.subjname as subject, b.pq1, b.pq2, b.pq3, b.pq4, b.pq5, b.pq6, b.pq7, b.pq8
            , b.pq9, b.pq10, b.pqrelm from $maindb a, $trandb b where a.vouchno = b.vouchno $subjcond $sesscond $examcond
             $schlcond $medmcond $rangecond group by a.custcode order by a.vouchno,a.accode") or die(mysqli_error($conn));

    $getno = mysqli_num_rows($gmain);

    if ($getno == 0) {
        browse("No Record Found");
        echo "<script>window.close()</script>";
    }

    include("includes/linkshead.php");
    ?>
    <link href="MyStyle/rep_format.css" rel="stylesheet">
    <style>


        .mtable{
            border:3px solid black;
        }
        .mtd{
            border:1px solid black;
            boder-collapse:collapse;
            text-align:right;
        }

        td,th{
            padding:15px;
            font-size:30px;
        }

        .border{
            border-top: none;
            border-right: 3px solid black;
            border-bottom: 3px solid black;
            border-left: none;    

        }

        .fsize{
            font-size:30px;
        }

        table{
            width:75%;
        }


    </style>
    </head>
    <body>
        <?php
        while ($fmain = mysqli_fetch_array($gmain)) {
            $accode = $fmain['accode'] ;
        
            switch ($std) {
                case "I":
                    $stdvar = $fmain['pq1'];
                    break;

                case "II":
                    $stdvar = $fmain['pq2'];
                    break;

                case "III":
                    $stdvar = $fmain['pq3'];
                    break;

                case "IV":
                    $stdvar = $fmain['pq4'];
                    break;

                case "V":
                    $stdvar = $fmain['pq5'];
                    break;

                case "VI":
                    $stdvar = $fmain['pq6'];
                    break;

                case "VII":
                    $stdvar = $fmain['pq7'];
                    break;

                case "VIII":
                    $stdvar = $fmain['pq8'];
                    break;

                case "IX":
                    $stdvar = $fmain['pq9'];
                    break;

                case "X":
                    $stdvar = $fmain['pq10'];
                    break;

                case "Prelim":
                    $stdvar = $fmain['pqrelm'];
                    break;
            }

            $gparc = mysqli_query($conn, "SELECT * from `accmast` WHERE `accode` = '$accode'") or die(mysqli_error($conn));
            $fparc = mysqli_fetch_array($gparc);

            if ($fparc['stcode'] != 0) {
                $parc = 'P';
            } elseif ($fparc['courcode'] != 0) {
                $parc = 'C';
            } else {
                $parc = '';
            }
            
     
            if ($stdvar > 1) {
                ?>
                <div class="page">
                    <div class="container">
                        <div class="col-lg-10"></div>
                        <div class="col-lg-2">
                            <!--<a  class="btn btn-primary goback align-left"  onclick="window.close()">Go Back</a>-->
                        </div>
                    </div>
                    <div class="subpage" style="margin-top:5px;width:100%;">
                        <?php ?>
                        <br>
                        <br>
                        <br>
                        <table align="center" class="mtable">
                            <tr height="85" class="border">
                                <td width="13%"  style="padding-right: 0px;font-size:35px;"><b>STD - </b></td>
                                <td width="48%" class="fsize border" style="font-size:35px;"><b><?php echo $std ; ?></b></td>
                                <td width="12%" class="border" style="font-size:40px;"><b><?php echo $parc; ?></b></td>
                            </tr>
                            <tr height="85">
                                <td style="font-size:23px;padding-right: 0px" ><b>SCHOOL NO.&nbsp;&nbsp;:</b></td>
                                <td style="font-size:38px;padding-left: 0px"  colspan="2" >&nbsp;<b><?php echo $fmain['custcode']; ?></b></td>
                            </tr>
                            <tr height="85">
                                <td style="font-size:23px;" colspan="" style="border-right:1px solid black;padding-right: 0px"><b>SUBJECT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</b></td>
                                <td style="font-size:21px;" colspan="2" style="border-right:1px solid black;padding-left: 0px"><b><?php echo $fmain['subject']; ?></b></td>    

                            </tr>
                            <tr height="85">
                                <td style="font-size:23px;padding-right: 0px"><b>QUANTITY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</b>
                                <td style="font-size:38px;padding-left: 10px" colspan="2"><b><?php echo $stdvar; ?></b></td>

                            </tr>
                        </table>
                    </div>
                </div>
                <?php
            }
        }
        ?>
        <?php include('includes/linksfoot.php'); ?>
    </body>
    </html>
    <?PHP
}


if (isset($_POST["a4"])) {
    $formname = ' Labels - Subject';
    $frmvouch = $_POST["fvouch"];
    $tovouch = $_POST["tvouch"];
    $section = $_POST["section"];
    $school = $_POST["name"];
    $medium = $_POST["medmcode"];
    $session = $_POST["session"];
    $subject = $_POST["subject"];
    $std = $_POST["std"];
    $exam = $_POST["exam"];

    $sectcond = "";
    $schlcond = "";
    $medmcond = "";
    $sesscond = "";
    $subjcond = "";
    $examcond = "";
    $rangecond = "";

    if (!empty($section)) {
        $sectcond = " AND a.`section` = '$section' ";
    }

    if (!empty($school)) {
        $schlcond = " AND a.`accode` = '$school' ";
    }

    if (!empty($medium)) {
        $medmcond = " AND a.`medmcode` = '$medium' ";
    }

    if (!empty($session)) {
        $sesscond = " AND a.`session` = '$session' ";
    }

    if (!empty($subject)) {
        $subjcond = " AND b.`subjcode` = '$subject' ";
    }


    if (!empty($exam)) {
        $examcond = " AND a.`examcode` = '$exam' ";
    }

    if (!empty($frmvouch)) {
        $rangecond = " and a.`vouchno` between $frmvouch and $tovouch ";
    }

    $gmain = mysqli_query($conn, "SELECT a.*, b.subjcode, b.subjname as subject, b.pq1, b.pq2, b.pq3, b.pq4, b.pq5, b.pq6, b.pq7, b.pq8
            , b.pq9, b.pq10, b.pqrelm from $maindb a, $trandb b where a.vouchno = b.vouchno $subjcond $sesscond $examcond
             $schlcond $medmcond $rangecond group by a.custcode order by a.vouchno, a.accode") or die(mysqli_error($conn));

    $getno = mysqli_num_rows($gmain);

    if ($getno == 0) {
        browse("No Record Found");
        echo "<script>window.close()</script>";
    }

    include("includes/linkshead.php");
    ?>
    <link href="MyStyle/rep_format.css" rel="stylesheet">
    <style>


        .mtable{
            border:3px solid black;
        }
        .mtd{
            border:1px solid black;
            border-collapse:collapse;
            text-align:right;
        }

        td,th{
            padding:15px;
            font-size:30px;
        }

        .border{
            border-top: none;
            border-right: 3px solid black;
            border-bottom: 3px solid black;
            border-left: none;    

        }

        .fsize{
            font-size:30px;
        }

        table{
            width:75%;
        }


    </style>
    </head>
    <body>
        <?php
        $al = 1;
        while ($fmain = mysqli_fetch_array($gmain)) {
            $accode = $fmain['accode'];

            switch ($std) {
                case "I":
                    $stdvar = $fmain['pq1'];
                    break;

                case "II":
                    $stdvar = $fmain['pq2'];
                    break;

                case "III":
                    $stdvar = $fmain['pq3'];
                    break;

                case "IV":
                    $stdvar = $fmain['pq4'];
                    break;

                case "V":
                    $stdvar = $fmain['pq5'];
                    break;

                case "VI":
                    $stdvar = $fmain['pq6'];
                    break;

                case "VII":
                    $stdvar = $fmain['pq7'];
                    break;

                case "VIII":
                    $stdvar = $fmain['pq8'];
                    break;

                case "IX":
                    $stdvar = $fmain['pq9'];
                    break;

                case "X":
                    $stdvar = $fmain['pq10'];
                    break;

                case "Prelim":
                    $stdvar = $fmain['pqrelm'];
                    break;
            }

            $gparc = mysqli_query($conn, "SELECT * from `accmast` WHERE `accode` = '$accode'") or die(mysqli_error($conn));
            $fparc = mysqli_fetch_array($gparc);

            if ($fparc['stcode'] != 0) {
                $parc = 'P';
            } elseif ($fparc['courcode'] != 0) {
                $parc = 'C';
            } else {
                $parc = '';
            }


            if ($stdvar > 1) {
                ?>
                <?php
                $toppad = "";
                switch ($al) {
                    case 1:
                        ?>
                        <div class="page">
                            <div class="subpage" style="margin-top:5px;width:100%;">
                                <br>
                                <br>
                                <br>
                                <br>
                                <br>
                                <?php
                                $side = 'left';

                                break;
                            case 2:
                                $side = 'right';
                                break;
                            case 3:
                                $toppad = "margin-top:25%";
                                $side = 'left';
                                break;
                            default:
                                $toppad = "margin-top:25%";
                               $side = 'right';
                                break;
                        }
                        ?>



                        <table align=<?= $side ?> class="mtable" style="width:45%;<?=$toppad?>">
                            <tr height="85" class="border">
                                <td width="13%"  style="padding-right: 0px;font-size:35px;"><b>STD - </b></td>
                                <td width="48%" class="fsize border" style="font-size:35px;"><b><?php echo $std; ?></b></td>
                                <td width="12%" class="border" style="font-size:40px;"><b><?php echo $parc; ?></b></td>
                            </tr>
                            <tr height="85">
                                <td style="font-size:18px;padding-right: 0px" ><b>SCHOOL NO.&nbsp;&nbsp;:</b></td>
                                <td style="font-size:38px;padding-left: 0px"  colspan="2" >&nbsp;<b><?php echo $fmain['custcode']; ?></b></td>
                            </tr>
                            <tr height="85">
                                <td style="font-size:18px;" colspan="" style="border-right:1px solid black;padding-right: 0px"><b>SUBJECT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</b></td>
                                <td style="font-size:15px;" colspan="2" style="border-right:1px solid black;padding-left: 0px"><b><?php echo $fmain['subject']; ?></b></td>    

                            </tr>
                            <tr height="85">
                                <td style="font-size:18px;padding-right: 0px"><b>QUANTITY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</b>
                                <td style="font-size:38px;padding-left: 10px" colspan="2"><b><?php echo $stdvar; ?></b></td>

                            </tr>
                        </table>
                        <?php
                        switch ($al) {
                            case 1:
                                $al = 2;
                                break;
                            case 2:

                                $al = 3;
                                break;
                            case 3:
                                $al = 4;
                                break;
                            default:
                                ?>
                            </div>
                        </div>
                        <?php
                        $al = 1;
                        break;
                }
            }
        }
        ?>
        <?php include('includes/linksfoot.php'); ?>
    </body>
    </html>
    <?PHP
}




?>