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

$maindb = 'accmast';
$formname = 'Label';
$para = $_GET["para"];
if ($para == 1) {
    $grpcode = '010';
} else {
    $grpcode = '009';
}
$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);
$mvouch = $_REQUEST["name"];
$scond = '';
$scond2 = '';

if ($para == 1) {
    if (!empty($mvouch)) {
        $scond = "AND `staff`='$mvouch'";
    } $cmain = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE `grpcode` = '$grpcode' $scond ORDER BY `name`")or die(mysqli_error($conn));
} else {
    if (!empty($mvouch)) {
        $scond2 = "AND `accode`='$mvouch'";
    } $cmain = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE grpcode='$grpcode' $scond2 ORDER BY `name`")or die(mysqli_error($conn));
}
$num = mysqli_num_rows($cmain);
?>
<html>
    <head>        
        <title><?= $formname ?></title>    
    </head>    
    <style type="text/css">        
        /*table { page-break-inside:auto }        tr    { page-break-inside:avoid; page-break-after:auto }        thead { display:table-header-group }        tfoot { display:table-footer-group }*/        
        table {            
            table-layout:fixed;            
            width:100%;        
        }        
        td {            
            height: 15px;        
        }    
    </style>        
    <body>        
        <table width="100%" border="0" cellspacing='0' cellpadding='0' style='height:30%;border: 0px solid red;'>            
            <?php
            $counter = 1;
            $ctr = 0;
            $breaker = 1;
            while ($ctmp = mysqli_fetch_object($cmain)) {
                if ($counter == 1) {
                    $name_1 = $ctmp->name;
                    $add1_1 = $ctmp->add1;
                    $add2_1 = $ctmp->add2;
                    $add3_1 = $ctmp->add3;
                    $city_1 = $ctmp->city;
                    $pin_1 = $ctmp->pin;
                    $station_1 = $ctmp->station;
                    $tel_1 = $ctmp->tel;
                    $mobile_1 = $ctmp->mobile;
                    echo "<td>";
                    echo "<font size='1.5px'>" . $name_1;
                    echo "</td>";
                } if ($counter == 2) {
                    $name_2 = $ctmp->name;
                    $add1_2 = $ctmp->add1;
                    $add2_2 = $ctmp->add2;
                    $add3_2 = $ctmp->add3;
                    $city_2 = $ctmp->city;
                    $pin_2 = $ctmp->pin;
                    $station_2 = $ctmp->station;
                    $tel_2 = $ctmp->tel;
                    $mobile_2 = $ctmp->mobile;
                    echo "<td>";
                    echo "<font  size='1.5px'>" . $name_2;
                    echo "</td>";
                } if ($counter == 3) {
                    $name_3 = $ctmp->name;
                    $add1_3 = $ctmp->add1;
                    $add2_3 = $ctmp->add2;
                    $add3_3 = $ctmp->add3;
                    $city_3 = $ctmp->city;
                    $pin_3 = $ctmp->pin;
                    $station_3 = $ctmp->station;
                    $tel_3 = $ctmp->tel;
                    $mobile_3 = $ctmp->mobile;
                    echo "<td>";
                    echo "<font  size='1.5px'>" . $name_3;
                    echo "</td>";
                    echo "<tr>";
                    echo "<td>";
                    if (!empty($add1_1)) {
                        echo "<font  size='1.5px'>" . $add1_1;
                    } else {
                        echo "<br/>";
                    } echo "</td>";
                    echo "<td>";
                    if (!empty($add1_2)) {
                        echo "<font  size='1.5px'>" . $add1_2;
                    } else {
                        echo "<br/>";
                    } echo "</td>";
                    echo "<td>";
                    if (!empty($add1_3)) {
                        echo "<font  size='1.5px'>" . $add1_3;
                    } else {
                        echo "<br/>";
                    } echo "</td>";
                    echo "</tr>";
                    echo "<tr>";
                    echo "<td>";
                    if (!empty($add2_1)) {
                        echo "<font  size='1.5px'>" . $add2_1;
                    } else {
                        echo "<br/>";
                    } echo "</td>";
                    echo "<td>";
                    if (!empty($add2_2)) {
                        echo "<font  size='1.5px'>" . $add2_2;
                    } else {
                        echo "<br/>";
                    } echo "</td>";
                    echo "<td>";
                    if (!empty($add2_3)) {
                        echo "<font  size='1.5px'>" . $add2_3;
                    } else {
                        echo "<br/>";
                    } echo "</td>";
                    echo "</tr>";
                    echo "<tr>";
                    echo "<td>";
                    if (!empty($add3_1)) {
                        echo "<font  size='1.5px'>" . $add3_1;
                    } else {
                        echo "<br/>";
                    } echo "</td>";
                    echo "<td>";
                    if (!empty($add3_2)) {
                        echo "<font  size='1.5px'>" . $add3_2;
                    } else {
                        echo "<br/>";
                    } echo "</td>";
                    echo "<td>";
                    if (!empty($add1_1)) {
                        echo "<font  size='1.5px'>" . $add3_3;
                    } else {
                        echo "<br/>";
                    } echo "</td>";
                    echo "</tr>";
                    echo "<tr>";
                    echo "<td>";
                    echo "<font  size='1.5px'>" . $city_1 . " " . $pin_1;
                    echo "</td>";
                    echo "<td>";
                    echo "<font  size='1.5px'>" . $city_2 . " " . $pin_2;
                    echo "</td>";
                    echo "<td>";
                    echo "<font  size='1.5px'>" . $city_3 . " " . $pin_3;
                    echo "</td>";
                    echo "</tr>";
                    echo "<tr>";
                    echo "<td>";
                    echo "<font  size='1.5px'>" . $station_1 . "</font>";
                    echo "</td>";
                    echo "<td>";
                    echo "<font  size='1.5px'>" . $station_2 . "</font>";
                    echo "</td>";
                    echo "<td>";
                    echo "<font  size='1.5px'>" . $station_3 . "</font>";
                    echo "</td>";
                    echo "</tr>";
                    echo "<tr>";
                    echo "<td>";
                    echo "<font  size='1.5px'>" . $tel_1 . " " . $mobile_1 . "</font>";
                    echo "</td>";
                    echo "<td>";
                    echo "<font  size='1.5px'>" . $tel_2 . " " . $mobile_2 . "</font>";
                    echo "</td>";
                    echo "<td>";
                    echo "<font  size='1.5px'>" . $tel_3 . " " . $mobile_3 . "</font>";
                    echo "</td>";
                    echo "</tr>";
                    echo "<tr>";
                    echo "<td>";
                    echo "</td>";
                    echo "</tr>";
                    $counter = 0;
                } $counter = $counter + 1;
                $ctr = $ctr + 1;
                if ($ctr == 24) {
                    echo "<tr>";
                    echo "<td>";
                    echo "</td>";
                    echo "</tr>";
                    echo "<tr>";
                    echo "<td>";
                    echo "</td>";
                    echo "</tr>";
                    $ctr = 0;
                }
            } if ($counter = 2) {
                echo "<tr>";
                echo "<td>";
                if (!empty($add1_1)) {
                    echo "<font  size='1.5px'>" . $add1_1;
                } else {
                    echo "<br/>";
                } echo "</td>";
                echo "</tr>";
                echo "<tr>";
                echo "<td>";
                if (!empty($add2_1)) {
                    echo "<font  size='1.5px'>" . $add2_1;
                } else {
                    echo "<br/>";
                } echo "</td>";
                echo "</tr>";
                echo "<tr>";
                echo "<td>";
                if (!empty($add3_1)) {
                    echo "<font  size='1.5px'>" . $add3_1;
                } else {
                    echo "<br/>";
                } echo "</td>";
                echo "</tr>";
                echo "<tr>";
                echo "<td>";
                echo "<font  size='1.5px'>" . $city_1 . " " . $pin_1;
                echo "</td>";
                echo "</tr>";
                echo "<tr>";
                echo "<td>";
                echo "<font  size='1.5px'>" . $station_1 . "</font>";
                echo "</td>";
                echo "</tr>";
                echo "<tr>";
                echo "<td>";
                echo "<font  size='1.5px'>" . $tel_1 . " " . $mobile_1 . "</font>";
                echo "</td>";
                echo "</tr>";
                echo "<tr>";
                echo "<td>";
                echo "</td>";
                echo "</tr>";
            } else {
                echo "<tr>";
                echo "<td>";
                if (!empty($add1_1)) {
                    echo "<font  size='1.5px'>" . $add1_1;
                } else {
                    echo "<br/>";
                } echo "</td>";
                echo "<td>";
                if (!empty($add1_2)) {
                    echo "<font  size='1.5px'>" . $add1_2;
                } else {
                    echo "<br/>";
                } echo "</td>";
                echo "</tr>";
                echo "<tr>";
                echo "<td>";
                if (!empty($add2_1)) {
                    echo "<font  size='1.5px'>" . $add2_1;
                } else {
                    echo "<br/>";
                } echo "</td>";
                echo "<td>";
                if (!empty($add2_2)) {
                    echo "<font  size='1.5px'>" . $add2_2;
                } else {
                    echo "<br/>";
                } echo "</td>";
                echo "</tr>";
                echo "<tr>";
                echo "<td>";
                if (!empty($add3_1)) {
                    echo "<font  size='1.5px'>" . $add3_1;
                } else {
                    echo "<br/>";
                } echo "</td>";
                echo "<td>";
                if (!empty($add3_2)) {
                    echo "<font  size='1.5px'>" . $add3_2;
                } else {
                    echo "<br/>";
                } echo "</td>";
                echo "</tr>";
                echo "<tr>";
                echo "<td>";
                echo "<font  size='1.5px'>" . $city_1 . " " . $pin_1;
                echo "</td>";
                echo "<td>";
                echo "<font  size='1.5px'>" . $city_2 . " " . $pin_2;
                echo "</td>";
                echo "</tr>";
                echo "<tr>";
                echo "<td>";
                echo "<font  size='1.5px'>" . $station_1 . "</font>";
                echo "</td>";
                echo "<td>";
                echo "<font  size='1.5px'>" . $station_2 . "</font>";
                echo "</td>";
                echo "</tr>";
                echo "<tr>";
                echo "<td>";
                echo "<font  size='1.5px'>" . $tel_1 . " " . $mobile_1 . "</font>";
                echo "</td>";
                echo "<td>";
                echo "<font  size='1.5px'>" . $tel_2 . " " . $mobile_2 . "</font>";
                echo "</td>";
                echo "</tr>";
                echo "<tr>";
                echo "<td>";
                echo "</td>";
                echo "</tr>";
            }
            ?>             
        </table>    
    </body>
</html>