<?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 = 'Multiple Envelope Print';
$code = $_REQUEST["code"];
$maindb = 'accmast';
$file = 'multienvp_select.php';

$count = $_POST['count'];
for ($i = 0; $i <= $count; $i++) {

    $chk = $_POST["chk_$i"];
    $custcode = $_POST["custcode_$i"];

    if ($chk == 1) {
        $mainqry = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE `custcode` = '$custcode' AND `grpcode` = '010' ") or die(mysqli_error($conn));

        include("includes/linkshead.php");
        ?>
        <html>
            <head>
                <title><?= $formanme ?></title>
                <style>
                    .page {
                        width: 220mm;
                        min-height: 100mm;
                        padding: 1mm;
                        margin: 0mm 0mm 0mm 4mm;
                        border: 1px #D3D3D3 solid;
                        border-radius: 5px;
                        background: white;

                    }
                    .subpage {
                        padding-right   : 0.5cm;
                        padding-left    : 0.5cm;
                        padding: 0cm; 
                        /*border: 1px solid;*/
                        height: 105.2mm;
                        outline: 2cm #ffffff solid;
                    }

                    body{
                        font-size: 23px;

                    }
                    table td{
                        font-size: 15px;
                    }
                    @media print{@page {size: landscape}}

                </style>
            </head>
            <body onload="window.print();">
                <?php while ($get = mysqli_fetch_object($mainqry)) { ?>
                    <br>
                    <div class="page" style="border: none">
                        <!--<div class="subpage">-->
                        <div style="width:55%;margin:auto;border:0px solid;padding-top:25px;">
                            <div>
                                <table width="100%">
                                    <tr>
                                        <td class="" style="text-align:left;padding-top: 35px; font-size:20;padding-left:60px;" >To,</td>
                                    </tr>
                                    <tr style="">
                                        <td style="text-align:left;padding-left:69px;"><span style="padding-right:15px;"></span>
                                            <b><?= $get->custcode ?></b><br/> 
                                            <span style="padding-right:15px"></span><b><?= $get->name ?></b><br/>
                                            <?php if (!empty($get->add1)) { ?>
                                                <span style="padding-right:15px"></span><?= $get->add1 ?><br/>
                                            <?php }if (!empty($get->add2)) { ?>
                                                <span style="padding-right:15px"></span><?= $get->add2 ?><br/>
                                            <?php }if (!empty($get->add3)) { ?>
                                                <span style="padding-right:15px"></span><?= $get->add3 ?><br/>
                                                <!--<span style="padding-right:25px"></span><?= $get->station ?><br/>-->
                                            <?php }if (!empty($get->city)) { ?>
                                                <span style="padding-right:15px"></span><?= $get->city ?> <?= $get->pin ?><br/>
                                            <?php }if (!empty($get->tel)) { ?>
                                                <span style="padding-right:15px"></span>
                                                <?php echo $get->tel . "/" . $get->mobile ?><br/>
                                            <?php }if (!empty($get->email)) { ?>
                                                <span style="padding-right:15px"></span><?= $get->email;
                            } ?>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
        <?php } ?>

        </body>
        <?php
    }
}
?>
</html>
