<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('max_input_vars', 8000);
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');

$formname = 'Change of Customer Detail';
$file = 'changecust.php';
$maindb = 'accmast';
$grpcode = '010';

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

if (isset($_POST['submit'])) {
    //  browse("submitted");
    mysqli_query($conn, "LOCK TABLES `accmast` WRITE") or die(mysqli_error($conn));
    $count = $_POST["count"];
    browse($count);
    if (isset($count)) {
        //   browse("GAYa");
        for ($i = 0; $i < $count; $i++) {

            $code = $_POST["code_$i"];
            $station = $_POST["station_$i"];
            $tel = $_POST["transporter_$i"];
            $mobile = $_POST["mobile_$i"];
            $staff = $_POST["staff_$i"];
            $credlimit = $_POST["limit_$i"];
            $openbal = $_POST["openbal_$i"];
            $dc = "D";

            mysqli_query($conn, "UPDATE `$maindb` SET `station`='$station', transporter = '$tel', mobile='$mobile', `staff`='$staff',
                    `credlimit`='$credlimit', `openbal`='$openbal', `dc`='$dc' WHERE accode='$code'") or die(mysqli_error($conn));
        }
        mysqli_query($conn, "UNLOCK TABLES") or die(mysqli_error($conn));
        updmess();
        header("refresh: 1; $file");
    }
}
?>
<!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">
        <style type='text/css'>
            #loader{
                position: absolute;
                left: 50%;
                top: 150px;
                display: block;
            }

        </style>
        <script type="text/javascript" src="js/jquery.js"></script>
        <script src="assets/lib/modernizr-build.min.js"></script>
        <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 type="text/javascript">
            (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');


            /*************FILTER***************/

            $(document).ready(function () {
                var activeSystemClass = $('.list-group-item.active');

                //something is entered in search form
                $('#system-search').keyup(function () {
                    var that = this;
                    // affect all table rows on in systems table
                    var tableBody = $('.table-list-search tbody');
                    var tableRowsClass = $('.table-list-search tbody tr');
                    $('.search-sf').remove();
                    tableRowsClass.each(function (i, val) {

                        //Lower text for case insensitive
                        var rowText = $(val).text().toLowerCase();
                        var inputText = $(that).val().toLowerCase();
                        if (inputText != '')
                        {
                            $('.search-query-sf').remove();
                            tableBody.prepend('<tr class="search-query-sf"><td colspan="6"><strong>Searching for: "'
                                    + $(that).val()
                                    + '"</strong></td></tr>');
                        }
                        else
                        {
                            $('.search-query-sf').remove();
                        }

                        if (rowText.indexOf(inputText) == -1)
                        {
                            //hide rows
                            tableRowsClass.eq(i).hide();

                        }
                        else
                        {
                            $('.search-sf').remove();
                            tableRowsClass.eq(i).show();
                        }
                    });
                    //all tr elements are hidden
                    if (tableRowsClass.children(':visible').length == 0)
                    {
                        tableBody.append('<tr class="search-sf"><td class="text-muted" colspan="6">No entries found.</td></tr>');
                    }
                });

                $('#staff').change(function () {
                    var staff = $("#staff").val();
                    $('#customerdata').empty();
                    $('#customerdata').append("<img id='loader' src='images/ajax_loader.gif' >");
                    $.post('get_customer_from_staff.php', {staff: staff}, function (data) {
                        $('#loader').hide();
                        $('#customerdata').html(data);

                    });
                });

                $('#empstaff').change(function () {
                    var staff = $("#empstaff").val();
                    $('#customerdata').empty();
                    $('#customerdata').append("<img id='loader' src='images/ajax_loader.gif' >");
                    $.post('get_empty_staff.php', {staff: staff}, function (data) {
                        $('#loader').hide();
                        $('#customerdata').html(data);

                    });
                });
            });

            /*************END---FILTER***************/

            $(document).keydown(function (event) {
                //19 for Mac Command+S
                if (!(String.fromCharCode(event.which).toLowerCase() == 's' && event.ctrlKey) && !(event.which == 19))
                    return true;
                //alert("Ctrl-s pressed");
                $("#submit").click();
                event.preventDefault();
                return false;
            });

            $(function () {
                metisTable();
                metisSortable();
            });
        </script>


    </head>
    <body>

        <form action='#' name='changecustdtl' method='POST'  enctype="multipart/form-data">
            <div class="row">
                <div class="col-lg-12">
                    <div class="box">
                        <header>
                            <h5></h5>
                            <center></center>
                            <div class="toolbar">
                                <div class="btn-group">

                                    <a href="#sortableTable" data-toggle="collapse" class="btn btn-default btn-sm minimize-box">
                                        <i class="fa fa-angle-up"></i>
                                    </a>
                                    <button class='btn btn-default btn-sm minimize-box' onclick="window.open('changecustlst.php?staff=' + document.getElementById('staff').value, 'popUpWindow', 'height=600,width=970,left=20,top=20, resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes');"/><i>Print</i></button> 
                                    <input id="submit" type='submit' name='submit' class='btn btn-sm   btn-primary' value='Save'/> 
                                </div>
                            </div>
                        </header>
                        <div class="input-group" style="width:400px;margin-top: 5px;margin-left: 10px;">

                            <input class="form-control" id="system-search" name="q" placeholder="Search for" style="height:34px;">
                            <span class="input-group-btn">
                                <input type="submit" name='submit' class="btn btn-default" /><i class="glyphicon glyphicon-search"></i>
                            </span>
                        </div>
                        <div class="input-group" style="width:400px;margin-top: -33px;margin-left: 437px;">
                            <select id="staff" class="form-control" style="height:34px;">
                                <option></option>
                                <option value='0'>ALL</option>
                                <?php
                                $getstaff = mysqli_query($conn, "SELECT code, `name` FROM `staff` ORDER BY `name`") or die(mysqli_error($conn));
                                while ($mrow = mysqli_fetch_object($getstaff)) {
                                    echo "<option value='$mrow->code'>$mrow->name</option>";
                                }
                                ?>
                            </select>
                        </div>
                        
                        <div class="input-group" style="width:200px;margin-top: -33px;margin-left: 857px; height:34px;">
                            <table>
                                <tr>
                                    <td>
                                        <label>Empty Staff</label>
                                    </td>
                                    <td>                                    
                                        <select placeholder="Empty Staff" id="empstaff" class="form-control" style="height:34px;">
                                            <option></option>
                                            <option value='1'>BLANK</option>                                
                                        </select>
                                    </td>
                                </tr>
                            </table> 
                        </div>
                               
                        <div  style="border:0px solid red;overflow: auto;height:auto;">
                            <div id="sortableTable" class="body collapse in">
                                <table id="customerdata" class="table table-list-search sortableTable table-bordered responsive-table">
                                    <img style='display:none;' id='loader' src='images/ajax_loader.gif' >
                                </table>                
                            </div>                
                        </div>
                    </div>
                </div>

            </div>
        </form>
    </body>
</html>
