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

$formname = 'metric ';
$maindb = 'metric';
$file = 'visaupd.php?mode=last&form=openbal';
$series = $_SESSION["society_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$zroot = $_SESSION["zdbroot"];

mysqli_select_db($conn,$zdb);

if (isset($_GET["mode"]) == "true") {
    $addflag = 1;
} else {
    $addflag = 0;
}

if (isset($_POST['submit'])) {
    $savetype = $_POST['savetype'];
    $totdebit = $_POST["totdebit"];
    $totcredit = $_POST["totcredit"];

    $count = $_POST["count"];
    $mcount = $_POST["count"];

    for ($i = 0; $i <= $mcount; $i++) {
        $paxid = $_POST['paxid_' . $i];
        $visano = $_POST['visano_' . $i];
        $mofa = $_POST['mofa_' . $i];
        $passportno = $_POST['passportno_' . $i];
        $visaisspl = $_POST['visaisspl_' . $i];

        mysqli_query($conn,"UPDATE `$maindb` SET `paxid`='$paxid', `visano`='$visano', `mofa`='$mofa', `passportno`='$passportno',`visaisspl`='$visaisspl'
                     WHERE paxid='$paxid' ") or die(mysqli_error($conn));
    }

    updmess();
    header("refresh: 1; $file");
}
$result = mysqli_query($conn,"SELECT * FROM `metric` ") or die(mysqli_error($conn));

include("includes/linkshead.php");
?>

<script>
    $(document).ready(function () {
         $('body').on('click', '.sbutton', filter);
//        $('body').on('change focus', '#cmbtype', loadmain);

        loadmain();
        function loadmain() {
            var cmbtype = $('#cmbtype').val();
//            if (cmbtype == 2) {
            $.ajax({
                type: "GET",
                url: "opnbalall.php",
                data: {code: cmbtype},
                success: function (result) {
                    $("#data").html(result);
//                        $('.divmem').hide();
                    calculatecal();
                }

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


        function filter() {
            var stype = $('.stype').val(),
                    sterm = $('#sterm').val();
            var cmbtype = $('#cmbtype').val();
            $.ajax({
                type: "GET",
                url: "opnbalall.php",
                data: {stype: stype, sterm: sterm},
                success: function (result) {
                    $("#data").html(result);
                }
            });



        }

        $("#cmbgrp").change(function () {
            var cmbgrp = '1';
            $.ajax({
                type: "GET",
                url: "opnbalall.php",
                data: {code: cmbgrp},
                success: function (result) {

                    $("#data").empty();
                    $("#data").html(result);
                }
            });
        });
        $("#siscon").change(function () {
            var siscon = $('#siscon').val();
            $.ajax({
                type: "GET",
                url: "opnbalall.php",
                data: {siscon: siscon},
                success: function (result) {

                    $("#data").empty();
                    $("#data").html(result);
                }
            });
        });

        $('#submit').click(function () {
            $('#bill').submit();
        });
    });
    $(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;
    });</script>
<body>
    <!-- main content start-->
    <div class="panel panel-widget forms-panel my-div width col-lg-12" >
        <form name="" class="validation" id="form" action="" method="post">
            <div class="forms">
                <div class="form-grids widget-shadow" data-example-id="basic-forms"> 
                    <div class="form-title">
                        <h4><?php echo $formname ?></h4>
                    </div>
                    <br>
                    <div class="form-group has-error divmem">
                        <label class="col-sm-1 control-label text-right">Search By</label>
                        <div class="col-sm-2">
                            <select id="stype" name="stype" style="height:35px;"  class="stype form-control">
                                <option value="1">Paxid</option>
                                <option value="2">Name</option>
                                <option value="3">Haji No</option>
                                <option value="4">Visa No</option>
                            </select>
                        </div>
                        <label class="col-sm-1 control-label text-right">Sister Concern</label>
                        <div class="col-sm-2">
                            <select id="siscon" name="siscon" style="height:35px;"  class="siscon form-control">
                                <option value=>
                                    <?php
                                    $getsis = mysqli_query($conn,"SELECT `siscono`, `name` FROM $zroot.`sisterconcern` ORDER BY `name` ") or die(mysqli_error($conn));
                                    while ($fetsis = mysqli_fetch_assoc($getsis)) {
                                        Echo "<option value='$fetsis[siscono]'>$fetsis[name]</option>";
                                    }
                                    ?>
                                </option>
                            </select>
                        </div>
                        <div class="col-sm-2">
                            <input type="text" id="sterm"  class="sterm form-control" style="height: 35px" value="">
                        </div>
                        <div class="col-sm-1">
                            <input type="button"   class="btn btn-primary sbutton " style="height: 35px" value="Search">
                        </div>
                    </div>

                </div>

            </div>
            <br>
            <div class="row">
                <div style="overflow: auto; border: 0px ;">
                    <div style="float:left;">
                        <div id='data' style="margin-right: 20px;margin-left:20px;overflow-y: scroll;height: 600px">
                        </div>                  
                    </div> 
                </div>
            </div>

            <div style="overflow: auto;">
                <table class="table-condensed" style="margin: 0 auto;">
                    <tr>
                        <td class="buttonform tooltip-bottom" id="ssubmit" style="display: <? Echo $savedisabled ?>" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="Save Record">
                            <button id='submit' type='submit' name='submit' value='<?php echo ($addflag == 0) ? "Update" : "Save"; ?>' class="btn btn-pad btn-square " style="background-color:#008D4C; ">
                                <i class="fa fa-check" style="color:#ffffff"></i>
                            </button>
                        </td>
                        <td class=" buttonform tooltip-bottom" id="hexit" style="display: <? Echo $exitdisabled ?>" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="Exit">
                            <button id='exit' type="button" class="btn btn-pad btn-square " style="background-color:#cccccc; "  onClick="window.location.href = '<?= 'default.php' ?>'">
                                <i class="fa fa-power-off" style="color:red"></i>
                            </button>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="row">
                <div style="overflow: auto; border: 0px ;">
                    <div style="float:left;">
                        <div id='data' style="margin-right: 47px;margin-left: 41px;"></div>                  
                    </div> 
                </div>
            </div>
        </form> 
    </div>

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