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

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

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

if (isset($_POST["view"])) {
   $name = $_POST[name];
    $area = $_POST[area];
    $city = $_POST[city];
    $pin = $_POST[pin];
    $address = $_POST[address];
    $member = $_POST[member];
    $brno = $_POST[brno];
    $groupmast = $_POST[groupmast];
    $cbsno = $_POST[cbsno];
    $oldno = $_POST[oldno];
    $orderby = $_POST[orderby];
    $region = $_POST[region];

    $namecond = "";
    $membercond = "";
    $areacond = "";
    $brnocond = "";
    $citycond = "";
    $pincond = "";
    $addresscond = "";
    $groupmastcond = "";
    $orderbycond = "";
    $cbscond = "";
    $oldcond = "";
    $regioncond = "";

    if (!empty($groupmast)) {
        $groupmastcond = " and accode in (select memcode from grouptran where code != '' and `code`='$groupmast')";
    }
    if (!empty($name)) {
        $namecond = " AND `accode`='$name' ";
    }
    if (!empty($member)) {
        $membercond = " AND `name` LIKE '%$member%' ";
    }
    if (!empty($address)) {
        $addresscond = "  AND ( `add1` LIKE '%$address%' or  `add2` LIKE '%$address%' or  `add3` LIKE '%$address%' )";
    }
    if (!empty($area)) {
        $areacond = " AND `station` LIKE '%$area%' ";
    }
    if (!empty($region)) {
        $regioncond = " AND `region` LIKE '%$region%' ";
    }
    if (!empty($brno)) {
        $brnocond = " AND `brno` LIKE '%$brno%' ";
    }
    if (!empty($pin)) {
        $pincond = " AND `pin` LIKE '%$pin%' ";
    }
    if (!empty($city)) {
        $citycond = " AND `city` LIKE '%$city%' ";
    }
    if (!empty($cbsno)) {
        $cbscond = " AND `cbsno` LIKE '%$cbsno%' ";
    }
    if (!empty($oldno)) {
        $oldcond = " AND `oldno` LIKE '%$oldno%' ";
    }

    $cmain = mysqli_query($conn,"SELECT * FROM `$maindb` WHERE name != '' $regioncond $cbscond $oldcond $namecond $addresscond $brnocond $membercond $pincond $citycond $areacond  $groupmastcond")or die(mysqli_error($conn));

    include("includes/linkshead.php");
    ?>
    <!--    <script src="MyScript/item.js" type="text/javascript"></script>-->
    </head>
    <body>
        <div class="container">
            <div class="row">
                <div class="col-lg-12 pad">
                    <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'><b>" . $name_1 . "</b>";
                                    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'><b>" . $name_2 . "</b>";
                                    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'><b>" . $name_3 . "</b>";
                                    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>
                </div>
            </div>
        </div>

        <?php include("includes/linksfoot.php"); ?>
    </body>
    </html>
    <?php
}
?>