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

$maindb = "address";
//$trandb = "saletran";
$formname = "Labels";
$file = "labels.php";

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
//mysqli_select_db($conn, $zdb);

$name = $_POST["name"];
$state = $_POST["state"];
$city = $_POST["city"];
$type = $_POST["type"];

$namecond = "";
$statecond = "";
$citycond = "";

if (!empty($name)) {
    $namecond = " AND `accode` = '$name' ";
}

if (!empty($city)) {
    $citycond = " AND `city` = '$city' ";
}

if (!empty($state)) {
    $statecond = " AND `state` = '$state' ";
}
if (!empty($type)) {
    if ($type == 1) {
        $typecond = " AND concat(add1,add2,add3) != ''  ";
    } else if ($type == 2) {
        $typecond = " AND  concat(add1,add2,add3) = '' ";
    }
}

$mainqry = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE accode !='' AND grpcode = '010' $namecond $statecond $citycond $typecond order by `name` ") or die(mysqli_error($conn));
// echo mysqli_num_rows($mainqry);
include("includes/linkshead.php");
?>
<link href="styles/rep_format.css" rel="stylesheet">
<style>
    body {
        font-size: 15px;

    }

    table {
        width: 100%;
        /*border : 1px solid black;*/
    }

    .center {
        text-align: center;
    }

    .left {
        text-align: left;
    }

    .right {
        text-align: right;
    }

    .padd {
        padding: 3px;
    }

    .fontsize {
        font-size: 12px;
    }

    .page {
        width: 210mm;
        min-height: 294mm;
        padding: 1mm;
        margin: 1mm auto;
        border: 1px #D3D3D3 solid;
        border-radius: 5px;
        background: white;
    }

    .subpage {
        /*padding-top: 1.5cm;*/
        padding-right: 0.5cm;
        padding-left: 0.5cm;
        /* padding: 0cm; */
        /* border: 1px solid; */
        height: 278mm;
    }

    @media print {
        .page {
            width: 210mm;
            min-height: 294mm;
            padding: 1mm;
            margin: 1mm auto;
            margin-top: 11px !important;
            border: 1px #D3D3D3 solid;
            border-radius: 5px;
            background: white;
        }

        .subpage {
            padding-right: 0.5cm;
            padding-left: 0.5cm;
            height: 278mm;
        }

        tr.spaceUnder>td {
            padding-bottom: 10px;
        }        
    }
</style>
</head>

<body>

    <?php
    $ctr = 0;
    $counter = 0;

    if ($getno < 2) {
        $td2 = 2 - $getno;
    } else {
        $td2 = fmod($getno, 2) + 1;
    }


    $lblctr = 0;
    $newpg = 0;
    $left = 0;

    while ($lbl = mysqli_fetch_array($mainqry)) {

        $ctr++;
        if ($ctr > 12) {
            $newpg = 0;
            echo "</div>";     // page 
            echo "</div>";     // subpage
        }

        $newpg++;
        if ($newpg == 1) {
            echo "<div class='page' style='margin-top:10px'>";
            echo "<div class='subpage' style=''>";
            $ctr = 1;
        }

        $left++;

        if ($left == 1) {
            ?>
            <table class="myTable" width="100%">
                <tr>
                    <td width="50%" style="padding-left:10px;">

                    <? } else if ($left == 2) { ?>
                    <td width="50%" style="padding-left:10px;">
                    <?php } ?>
                    <table class="table-hover">
                        <tr style="height:16px">
                            <td class="padd fontsize"><b>&nbsp;<?php echo $lbl['name']; ?></b></td>
                        </tr>
                        <tr style="height:16px">
                            <td class="padd fontsize">&nbsp;<?php echo $lbl["add1"]; ?></td>
                        </tr>
                        <tr style="height:16px">
                            <td class="padd fontsize">&nbsp;<?php echo $lbl["add2"]; ?></td>
                        </tr>
                        <tr style="height:16px">
                            <td class="padd fontsize">&nbsp;<?php echo $lbl["add3"]; ?></td>
                        </tr>
                        <tr style="height:16px">
                            <td class="padd fontsize">&nbsp;<?php echo $lbl["city"] . " " . $lbl["pin"]; ?></td>
                        </tr>
                        <tr style="height:16px">
                            <td class="padd fontsize">&nbsp;<?php echo "Tel" . " - " . $lbl['tel']; ?></td>
                        </tr>
                        <tr class="spaceUnder" style="height:15px">
                            <td class="padd fontsize">&nbsp;<?php echo "Mobile" . "&nbsp;" . "-" . "&nbsp;" . $lbl['mobile']; ?></td>
                        </tr>
                        <br>
                    </table>
                </td>

                <?php
                if ($left == 2) {

                    echo "</tr>";
                    echo "</table>";
                    echo "<br>";

                    $left = 0;
                }
            }
            ?>