<?php
ini_set ("display_errors", "1");

error_reporting(E_ALL);
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
require("includes/function.php");

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


$result = mysqli_query($conn, "SELECT a.accode, a.name, a.mobile, a.station, a.mobile2, sum(b.amount)as balance FROM accmast a, actran b where 
                  a.grpcode = '010' and a.mobile !='' and a.accode=b.accode and b.chqret != 'Y' GROUP BY a.accode ORDER BY a.name  ")or die(mysqli_error($conn));
?>
<!DOCTYPE HTML>

<html lang="en-US"  xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="UTF-8">
        <meta name="msapplication-TileColor" content="#5bc0de"/>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <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="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>

        <style type="text/css">
            #table-wrapper {
                position:relative;
            }
            #table-scroll {
                height:499px;
                width:714px;
                overflow:auto;
                margin-top:20px;
            }
            #table-wrapper table {
                width:60%;

            }
            #table-wrapper table * {
                background:palegoldenrod;
                color:black;
            }
            #table-wrapper table thead th .text {
                position:absolute;   
                top:-20px;
                z-index:2;
                height:20px;
                width:35%;
                border:1px solid red;
            }
        </style>
        <script>
    $(function () {
        $("#example1").DataTable();
        $('#example2').DataTable({
            "paging": true,
            "lengthChange": false,
            "searching": false,
            "ordering": true,
            "info": true,
            "autoWidth": false
        });
    });
</script>
        <script>
            $(document).ready(function(){
                $("#sms").keyup(function(){
                    $('input[type="text"]').val(refresh());
                });
            });
        </script>
        <!--<fieldset style="border: 1px solid #CDCDCD; padding: 8px; padding-bottom:0px; margin: 8px; width:50%; height:50%;">-->
            <!--<legend><strong>SMS Address</strong></legend>-->
    <strong>SMS To Customer O/S</strong>
    <form name="myform" id="devel-generate-content-form" action="smsos.php" method="post">
        <!--<div style="float:left;">-->
    <!--            <table cellpadding="4" cellspacing="4" border="0" width="100% height='50%' ">-->
<!--         <div class="form-item form-type-checkbox form-item-node-types-webform">
                    <input type="checkbox" id="edit-node-types-webform" name="node_types[webform]"
                    value="webform" class="form-checkbox" />
                    <input type="text" id="edit-count-checked-checkboxes" name="count-checked-checkboxes" value="0" size="60" maxlength="50" class="form-text required" />-->
        <div id="table-wrapper" style='float:left;width:50%;height:100%;'>
            <div id="table-scroll" class="body">
                <table  id="example1" class="table-bordered table-condensed table-hover table-striped" style="width:100%;height:100%;">
                    <thead>
                        <tr>
                            <th style='text-align: left;width:50%;'>
                                Name
                            </th>
                            <th  style='text-align: left;width:30%;'>
                                Station
                            </th>
                            <th  style='text-align: left;width:20%;'>
                                Mobile
                            </th>                            
                            <th  style='text-align: left;width:20%;'>
                                Balance
                            </th>
                            <th  style='text-align: left;width:20%;'>
                                Mark
                            </th>
                            <!--<th><input name="selectall" id="selectall" value="1" type="checkbox" /></th>-->
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $i =0;
                        
                        while ($row = mysqli_fetch_array($result)) {
                            $balance = $row["balance"] * -1;
//                            $balance = $bal*-1;
                            echo "<tr>";
                            echo "<td align='left'>$row[name]</td>";
                            echo "<td align='left'>$row[station]</td>";
                            echo "<td align='left'>$row[mobile]</td>";
                            echo "<td align='left'>$balance</td>";
                            ?>
                        <td>
                            <input type="checkbox" value="<? echo $row['mobile']; ?>" id="check_list" class="chk" name="check_list[]" />
                        </td>
                            <!--<input name="check_list_$i" type='checkbox' id='check_list' class='chk' value='<? echo $row['mobile']; ?>'></td>";-->
                            <?php
                            echo "</td>";
                            echo "</tr>";
                            $i++;
                        }
                        ?>
                       
                    </tbody>
                </table>
                
            </div>
        </div>
        <div style='float:right;width:50%;'>
            <table align="center">
                <tr style="height:50px;"></tr>
                <tr align="left">
                    <td align="right">
                        <b>
                            Select / Unselect All
                        </b> 
                    </td>
                    <td align="left">
                        
                        <input type="checkbox" name="Check_ctr" onchange="checkAll(this)" id="example-select-all" class="chk" value="<?php echo $row['mobile'];  ?>"
                                onClick="Check(document.myform.check_list)">
                    </td>              
                </tr>   
                <tr align="right">
                    <td align="right">
                        <b>
                            Selected No.
                        </b>
                    </td>

                    <td align="left">
                        <input type="number" style="width:20%;" name="selected" id="selected" class="selected" value="0">
                    </td>              
                </tr>   
                
                
                <tr align="right">
                    <td align="right"  style='text-align:right;'>
                        <b>
                            Message
                        </b>
                    </td>
                    <td align="left">
                        <p style="padding:0px; margin: 0px;">
                            <textarea rows="5" cols="50" name="sms" id="sms"></textarea>
                            <!--maxlength="160"-->
                        </p>
                    </td>              
                </tr>   

                <tr>
                    <td>
                    </td>
                    <td>
                        <p style="padding:0px; margin: 0px;">
                            <input type="text" name="cnt" id="cnt" value="0" disabled="disabled" style="width: 50px; background:#66FFCC; color:red; font-weight: bold; "/>
                        </p>
                    </td>              
                </tr>   
                <tr>
                    <td align="right">
                        <label>ALERT</label>
                    </td>
                    <td>
                        <p style="padding:0px; margin: 0px;">
                            <input type="text" name="alert" id="alert" value="" style="font-weight: bold; "/>
                        </p>
                    </td>              
                </tr>   
                <tr>   
<!--                    <td>
                        <input type="text" name="selchk" id="selchk" value=<?=$i;?>/>
                    </td>-->
                    <td>
                        <p style="padding:4px; margin: 4px;">
                            <input type="submit" name="submit" id="submit" value="Send" />
                        </p>
                    </td>
                </tr>  
            </table>                
        </div>

      
        <div style="clear:both"></div>
    </form>
    <!--</fieldset>-->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#sms").keypress(function () {
                var sms = $(this).val().length;
                if (sms >= 320) {
                    $(this).attr("maxlength", "320");
                }
            $("#cnt").val(sms);
        });

    });
</script>
<script type="text/javascript">
    $(document).ready(function(){
    var $checkboxes = $('#devel-generate-content-form td input[type="checkbox"]');
    $checkboxes.change(function(){
            
        var countCheckedCheckboxes = $checkboxes.filter(':checked').length;
        $('#selected').val(countCheckedCheckboxes);
    });
});
</script>
    
  <script type="text/javascript">
        var total = 0;

        $(".chk").click(function () {

            var output = $.map($('.chk:checked'), function (n, i) {
                return n.value;
                return i.value;
            }).join(',');

//            total = $('.chk:checked').length;
//            $("#selected").val(total);
//            $('#selchk').VAL(countCheckedCheckboxes);
            $("#selchk").val(output);

        });

    </script>
<script type="text/javascript">
    function checkAll(ele) {
     var checkboxes = document.getElementsByTagName('input');
     if (ele.checked) {
         for (var j = 0; j < checkboxes.length; j++) {
             if (checkboxes[j].type == 'checkbox') {
                 checkboxes[j].checked = true;
             }
         }
     } else {
         for (var j = 0; j < checkboxes.length; j++) {
             console.log(j)
             if (checkboxes[j].type == 'checkbox') {
                 checkboxes[j].checked = false;
             }
         }
     }
 }
 </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.dataTables1.js"></script>
    <script src="assets/lib/datatables/DT_bootstrap1.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> 