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

$zdb = $_SESSION["zdbyear_" . $dbname];
//mysqli_select_db($conn, $zdb);
$formname = 'Envelope Print';

$file = 'multienv_fr.php';
$maindb = 'address';

$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));
?>
<html>

<head>
    <title><?= $formname ?></title>
    <style>
        @page {
            margin-left: 10%;
        }

        body {
            margin-left: 19%;
            width: 220.98mm;
            height: 109.22mm;
        }

        .footclass {
            page-break-after: always;
        }

        @media print {
            @page {
                margin-top: 30px;
                margin-left: 60px;

                size: 4.0in 8.0in;
                size: landscape;
                page-break-after: always;
            }

            .footclass {
                page-break-after: always;
            }

            .noPrint{
                display: none;
            }

        }
    </style>
</head>

<body>

    <div class="panel-heading noPrint">
        <br>
        <h3 class="panel-title" style="color:red">Note : Select Paper Size As Envelope DL.</h3>
    </div>

    <?php while ($row = mysqli_fetch_array($mainqry)) { ?>
        <div style="margin:auto;border:0px solid;padding-top:30px;" class="page">
            <table>
                <tr>
                    <td>
                        <font style="font-size: 26px;font-weight: bolder"><?= $row['name'] ?>
                        </font>
                    </td>
                </tr>

                <tr>
                    <td>
                        <?php
                        if ($row['add1'] != '') {
                            $row['add1'] ?>
                            <br />
                        <?php }

                        if ($row['add2'] != '') { ?>
                            <font style="font-size: 19px;"><?= $row['add2'] ?><br />
                            <?php }
                        if ($row['add3'] != '') { ?>
                                <?= $row['add3'] ?><br />
                            <?php } ?>
                    </td>
                </tr>

                <tr>
                    <td>
                        <?= $row['state'] ?>
                        <font style="font-size: 20px;font-weight: bolder"><?= $get->city ?> </font><?= $row['pin'] ?>
                    </td>
                </tr>
                <tr>
                    <td>
                        <?php
                        if (!empty($row['tel'])) {
                            echo $row['tel'] . " / ";
                        }
                        ?> <?= $row['mobile'] ?>
                    </td>
                </tr>
                </font>
            </table>
        </div>
        <p class='footclass'>

        <?php } ?>
</body>

</html>