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

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

if (isset($_POST["submit"])) {
//browse("$_POST[dtype]");
    $cond = "";
    $ccond = "";
    $cocond = "";
    $stcond = "";

    if (!empty($_POST["name"])) {
        $pname = trim($_POST["name"]);
        $cond = "AND `name` LIKE '%$pname%'";
    }

    if (!empty($_POST["country"])) {
        $country = trim($_POST["country"]);
        $cocond = "AND `country` LIKE '%$country%'";
    }
    if (!empty($_POST["station"])) {
        $city = trim($_POST["station"]);
        $ccond = "AND `station` LIKE '%$city%'";
    }

    if (!empty($_POST["staff"])) {
        $st = trim($_POST["staff"]);
        $stcond = "AND `staff`='$st'";
    }


    $get = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `name`!='' $cond $ccond $cocond $stcond AND `grpcode`='010' ORDER by `station`, `name`") or die(mysqli_error($conn));
    $getno = mysqli_num_rows($get);

    /* Normal Browser View Part */
    ?>    
    <!DOCTYPE HTML>
    <html lang="en-US">

        <head>
            <meta charset="UTF-8">
            <title><?php echo $formname; ?></title>
            <meta name="msapplication-TileColor" content="#5bc0de"/>
            <meta name="msapplication-TileImage" content="assets/img/metis-tile.png"/>

            <link rel="stylesheet" href="assets/lib/bootstrap/css/bootstrap.css">
            <link rel="stylesheet" href="assets/css/main.css"/>
            <link rel="stylesheet" href="assets/lib/Font-Awesome/css/font-awesome.css"/>

            <link rel="stylesheet" href="assets/css/theme.css">


            <link rel="stylesheet" href="assets/lib/uniform/themes/default/css/uniform.default.css">
            <link rel="stylesheet" href="assets/lib/inputlimiter/jquery.inputlimiter.1.0.css">
            <link rel="stylesheet" href="assets/lib/chosen/chosen.min.css">
            <link rel="stylesheet" href="assets/lib/colorpicker/css/colorpicker.css">
            <link rel="stylesheet" href="assets/lib/tagsinput/jquery.tagsinput.css">
            <link rel="stylesheet" href="assets/lib/daterangepicker/daterangepicker-bs3.css">
            <link rel="stylesheet" href="assets/lib/datepicker/css/datepicker.css">
            <link rel="stylesheet" href="assets/lib/timepicker/css/bootstrap-timepicker.min.css">
            <link rel="stylesheet" href="assets/lib/switch/static/stylesheets/bootstrap-switch.css">
            <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/flick/jquery-ui.css">


            <script>
                (function(i, s, o, g, r, a, m) {
                    i['GoogleAnalyticsObject'] = r;
                    i[r] = i[r] || function() {
                        (i[r].q = i[r].q || []).push(arguments)
                    }, i[r].l = 1 * new Date();
                    a = s.createElement(o),
                            m = s.getElementsByTagName(o)[0];
                    a.async = 1;
                    a.src = g;
                    m.parentNode.insertBefore(a, m)
                })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');

                ga('create', 'UA-1669764-16', 'onokumus.com');
                ga('send', 'pageview');

            </script>

            <script src="assets/lib/modernizr-build.min.js"></script>
            <script type="text/javascript" src="../js/jquery.js"></script>

            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

        </head>
        <body>

            <?php
            /*  require("includes/dbconnect.php");
              $comp = mysqli_query($conn, "SELECT * FROM `company`") or die(mysql_errno());
              $zcomp = mysqli_fetch_assoc($comp);
              echo "<font size='4px' color='#039'><b>$zcomp[compname]</font></b></font><br />";
              echo "<font size='2px' color='#039'><b> $zcomp[add1]. $zcomp[add2].  $zcomp[add3] </b></font><br /><br />";
              echo "<b><font color='#039'>Customer List &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font size='3px'>Date : ".date("M-d-Y") . "</b><br />";
              echo "<b>"."Total Customer - $getno</b><br />";
              echo "<br />"; */
            ?>

            <table class="table table-bordered sortableTable responsive-table" width="100%">

                <thead>
                    <tr>
                        <th style="text-align:left;" scope="col" width="6"><b>Sr.</b></th>
                        <?php
                        if ($_POST["dtype"] == 2) {
                            ?>
                            <th style="text-align:left;" scope="col" width="120"><b>Name & Address</b></th>
                        <?php } else { ?>
                            <th style="text-align:left;" scope="col" width="120"><b>Name</b></th>
                            <th style="text-align:left;" scope="col" width="120"><b>Station</b></th>
                            <th style="text-align:left;" scope="col" width="120"><b>Contact Person</b></th>
                            <th style="text-align:right;" scope="col" width="120"><b>Credit Limit</b></th>
                            <th style="text-align:right;" scope="col" width="120"><b>Opening Balance</b></th>
                        <?php } ?>
                        <th style="text-align:left;" scope="col" width="120"><b>Telephone</b></th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    $ctr = 0;
                    while ($city = mysqli_fetch_assoc($get)) {
                        $ctr++;
                        echo "<tr> \n";
                        echo "<td style=\"text-align:left;\" width=\"6\" valign='top'> \n <span> $ctr </span> \n </td> \n";
                        if ($_POST["dtype"] == 2) {
                            echo "<td style=\"text-align:left;\" width=\"180\" valign='top'> \n <span><b> $city[name]</b> </span> \n<br/>";
                            if (($city["add1"]) != " ") {
                                echo "<b>$city[add1]</b></font> </span><br/>
                                     <span> $city[add2] </span> \n <br/> <span> $city[add3] </span> \n <br/>";
                            }
                            if (($city["city"]) != " ") {
                                echo "<span> $city[station] </span> <span> $city[pin] </span> \n <br/></td>";
                            }
                        } else {
                            echo "<td style=\"text-align:left;\" width=\"6\" valign='top'> \n <span> $city[name] </span> \n </td> \n";
                            echo "<td style=\"text-align:left;\" width=\"6\" valign='top'> \n <span> $city[station] </span> \n </td> \n";
                            echo "<td style=\"text-align:left;\" width=\"6\" valign='top'> \n <span> $city[contpers] </span> \n </td> \n";
                            echo "<td style=\"text-align:left;\" width=\"6\" valign='top'> \n <span> $city[credlimit] </span> \n </td> \n";
                            echo "<td style=\"text-align:left;\" width=\"6\" valign='top'> \n <span> $city[openbal] </span> \n </td> \n";
                        }
                        echo "<td style=\"text-align:left;\" width=\"120\" valign='top'> \n <span><b> $city[tel]</b> </span> \n </td> \n";
                    }
                    ?>
                </tbody>
                <tfoot>
                    <tr>
                        <td colspan="9">
                            <hr/>
                        </td>
                    </tr>
                </tfoot>
            </table>
        
        <script src="assets/lib/jquery.min.js"></script>
        <script src="assets/lib/bootstrap/js/bootstrap.min.js"></script>

        <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
        <script src="assets/lib/datatables/jquery.dataTables.js"></script>
        <script src="assets/lib/datatables/DT_bootstrap.js"></script>
        <script src="assets/lib/tablesorter/js/jquery.tablesorter.min.js"></script>
        <script src="assets/lib/touch-punch/jquery.ui.touch-punch.min.js"></script>
        <script src="assets/js/main.min.js"></script>
        <script>
            $(function() {
                metisTable();
                metisSortable();
            });
        </script>
    </body>
    </html>

    <?php
}
?>