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

$formname = 'Update Form';
$maindb = 'bookform';
// $trandb = 'mehram';
// $printfile = "paxform_pdf.php";
$file = 'updform.php';
// $trandbexist = 1;
$keyfld = "vouchno";
$source = "";

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
$compcd = $_SESSION["comp_" . $dbname];
$tourname = $_SESSION['tourname'];
$tourcode = $_SESSION['tourcode'];
$tourcond = "AND tourno = '$tourcode'";
$zroot = $_SESSION["zdir"];

mysqli_select_db($conn, $zdb);
include("includes/vouchno_generate.php");
include("includes/prev&next.php");

if (isset($_POST["submit"])) {
    $a = 1;

    $regnfrmcond = "";
    $regntocond = "";
    $batchnocond = "";
    $agentcond = "";

    $regnfrm = $_POST["regnfrm"];
    $regnto = $_POST["regnto"];
    $batchno = $_POST["batchno"];
    $agent = $_POST["agent"];

    $a = 0;
    if ($regnfrm != '') {
        $regnfrmcond = " and regnno >= '$regnfrm' ";
        $a = 1;
    }
    if ($regnto != '') {
        $regntocond = " and regnno <= '$regnto' ";
        $a = 1;
    }
    if ($batchno != '') {
        $batchnocond = " and batchno = '$batchno' ";
        $a = 1;
    }
    if ($agent != '') {
        $agentcond = " and agent = '$agent' ";
        $a = 1;
    }

    if ($a == 0) {
        browse('Any One Element For Record Should Be Filled');
        return;
    }


    if ($a == 1) {
        $qvouch = $_POST["vouchno"];
        foreach ($_POST as $key => $value) {
            $exclude_fld = ["test"];
            if (in_array($key, $exclude_fld)) {
                continue;
            }
            $$key = $value;
            // echo "Field ".htmlspecialchars($key)." is ".htmlspecialchars($value)."<br>";
        }
        $count = $_POST["items"];
        $mvouch = $qvouch;
        $salecode = 11;


        #################################TRAN PART #################################

        $srl = 0;
        $batch = date("Y-m-d") . $mvouch;

        $mname = $surname . " " . $lastname . " " . $midname;
        #################################TRAN PART END #################################
        ############################## MAIN ######################################################

        $mvouch = $qvouch; //1
        mysqli_query($conn, "UPDATE `$maindb` SET `craft`='$craft', `sector`='$sector', `depdate`='$depdate', `deptime`='$deptime',
             `depflt`='$depflt',`deppnr`='$deppnr',`arrdate`='$arrdate', `arrtime`='$arrtime', `arrpnr`='$arrpnr', 
             `arrflt`='$arrflt' WHERE vouchno != '' $tourcond $regnfrmcond $regntocond $batchnocond $agentcond  ") or die(mysqli_error($conn));
        updmess();
        header("refresh: 1; $file?$keyfld=$mvouch&mode=true");
        ################################# MAIN PART END #################################
    }
}
include("includes/linkshead.php");
?>
<style>
    .nav-tabs {
        text-transform: uppercase;
        font-weight: bold;
        width: 1400px;
    }

    .subhead {
        text-align: center;
        text-decoration: underline;
    }
</style>
<script src="MyScript/shortkeys.js?a=2" type="text/javascript"></script>
<script src="MyScript/paxform.js?a=3" type="text/javascript"></script>
<script src="MyScript/paxform_search.js?a=2" type="text/javascript"></script>
</head>

<body>
    <form method='POST' action="" enctype="multipart/form-data">
        <!-- Default box -->
        <div>
            <div class="col-lg-8 col-md-10 col-sm-12 col-xs-12  pad">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title" style="color:inherit"><?php echo $formname; ?></h3>
                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-lg-12 col-md-3 col-sm-3 col-xs-3 text-center pad" style="background-color:#2fbffe;width: 981px; margin-left: 16px; border-radius: 4px;">
                                <label class="label-control marg" style="color:#ffffff;font-weight: bold" > For Record </label>
                            </div>
                        </div>
                        <BR>
                        
                        <div class="row">
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Tour</label>
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2  pad">
                                <select name="tour" id="tour" class="form-control form tour select2" style="width:100%">
                                    <option value="<?php echo  $tourcode; ?>"><?php echo $tourname; ?></option>
                                </select>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Regn No. From</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-4 col-xs-4  pad">
                                <input type="number" class="form-control regnfrm form" name="regnfrm" value="">
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Regn. No. To</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-4 col-xs-4  pad">
                                <input type="number" class="form-control regnto form" name="regnto" value="">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Class No</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-4 col-xs-4  pad">
                                <input list="batchno" name="batchno" class="batchno form-control form" value="" autocomplete="off">
                                <datalist id="batchno">

                                    <option value=""></option>
                                    <?php
                                    $mbatchno = mysqli_query($conn, "SELECT batchno FROM `$maindb` group by batchno order by batchno") or die(mysqli_error($conn));

                                    while ($tbat = mysqli_fetch_array($mbatchno)) {
                                        $batchnot = $tbat['batchno'];
                                        echo "<option value='$batchnot'>";
                                    }
                                    ?>
                                </datalist>
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Agent</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-4 col-xs-4  pad">
                                <input list="agent" name="agent" class="agent form-control form" value="<?php echo ($addflag != 1) ? $get["agent"] : ""; ?>" autocomplete="off">
                                <datalist id="agent">

                                    <option value=""></option>
                                    <?php
                                    $magenttt = mysqli_query($conn, "SELECT name FROM `accmast` where grpcode = '022' group by name order by name") or die(mysqli_error($conn));

                                    while ($tage = mysqli_fetch_array($magenttt)) {
                                        $agentt = $tage['name'];
                                        echo "<option value='$agentt'>";
                                    }
                                    ?>
                                </datalist>
                            </div>
                        </div>

                        <BR>
                        <div class="row">
                            <div class="col-lg-12 col-md-3 col-sm-3 col-xs-3 text-center pad" style="background-color:#50C878;width: 981px; margin-left: 16px; border-radius: 4px;">
                                <label class="label-control marg" style="color:#ffffff;font-weight: bold" > Update Below </label>
                            </div>
                        </div>
                        <BR>
                        <div class="row">
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Airline / Carrier</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-4 col-xs-4  pad">
                                <input list="craft" name="craft" class="craft form-control form" value="" autocomplete="off">
                                <datalist id="craft">

                                    <option value=""></option>
                                    <?php
                                    $mcraft = mysqli_query($conn, "SELECT craft FROM `$maindb` group by craft order by craft") or die(mysqli_error($conn));

                                    while ($tct = mysqli_fetch_array($mcraft)) {
                                        $craftt = $tct['craft'];
                                        echo "<option value='$craftt'>";
                                    }
                                    ?>
                                </datalist>
                            </div>
                            <div class="col-lg-3 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Sector</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-4 col-xs-4  pad">
                                <input list="sector" name="sector" class="sector form-control form" value="" autocomplete="off">
                                <datalist id="sector">

                                    <option value=""></option>
                                    <?php
                                    $msector = mysqli_query($conn, "SELECT sector FROM `$maindb` group by sector order by sector") or die(mysqli_error($conn));

                                    while ($tst = mysqli_fetch_array($msector)) {
                                        $sectort = $tst['sector'];
                                        echo "<option value='$sectort'>";
                                    }
                                    ?>
                                </datalist>
                            </div>
                        </div>
                        <br>
                        <div class="row">
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Dep Date</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-4 col-xs-4  pad">
                                <input type="date" class="form-control depdate form" name="depdate" value="">
                            </div>
                            <div class="col-lg-3 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Time</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-4 col-xs-4  pad">
                                <input type="time" class="form-control deptime form" name="deptime" value="">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Dep PNR</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-4 col-xs-4  pad">
                                <input type="text" class="form-control deppnr form" name="deppnr" value="">
                            </div>
                            <div class="col-lg-3 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Dep. Flt.No.</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-4 col-xs-4  pad">
                                <input type="text" class="form-control depflt form" name="depflt" value="">
                            </div>
                        </div>
                        <br>
                        <div class="row">
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Arrival Date</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-4 col-xs-4  pad">
                                <input type="date" class="form-control arrdate form" name="arrdate" value="">
                            </div>
                            <div class="col-lg-3 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Time</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-4 col-xs-4  pad">
                                <input type="time" class="form-control arrtime form" name="arrtime" value="">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Arrival PNR</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-4 col-xs-4  pad">
                                <input type="text" class="form-control arrpnr form" name="arrpnr" value="">
                            </div>
                            <div class="col-lg-3 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Arrival Flt.No.</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-4 col-xs-4  pad">
                                <input type="text" class="form-control arrflt form" name="arrflt" value="">
                            </div>
                        </div>
                    </div>

                    <div class="panel-footer" style="padding:0px;">
                        <div class="row">
                            <div class="col-lg-10 col-md-7 col-sm-8 col-xs-8 text-right pad">
                                <?php include("includes/buttsale.php"); ?>
                             
                            </div>
                        </div>
                    </div>
                </div>
            </div>
    </form>

    <div class="modal fade bs-example-modal-lg searchModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span>&times;</span></button>
                    <h4 class="modal-title" id="myLargeModalLabel">Search <? echo $formname; ?></h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-lg-2">
                            <select class="form-control sfield">
                                <option value="1">Voucher</option>
                                <option value="2">Date</option>
                                <option value="3">Name</option>
                                <option value="4">SurName</option>
                                <option value="5">Regn No.</option>
                                <option value="6">Mofano</option>
                                <option value="7">DOB</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control soperator">
                                <option value="">Type of Search</option>
                                <option value="%">Like</option>
                                <option value="=">Exactly</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control sortBy">
                                <option value="">Sort By</option>
                                <option value="1">Voucher</option>
                                <option value="2">Date</option>
                                <option value="3">Name</option>
                                <option value="4">SurName</option>
                                <option value="5">Regn No.</option>
                                <option value="6">Mofano</option>
                                <option value="7">DOB</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control orderAs">
                                <option value="desc">Desc</option>
                                <option value="asc">Asc</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <input type="text" value="" class="form-control ssearch" placeholder="Search Here">
                        </div>
                        <div class="col-lg-2">
                            <input type="button" class="btn btn-primary sload" value="Search">
                        </div>
                    </div>
                    <div class="col-lg-12 sloader text-center">
                    </div>
                    <div class="col-lg-12 snoRecord text-center">
                        <h3>NO RECORDS FOUND</h3>
                    </div>
                    <div class="table-responsive" style="max-height: 400px;overflow: auto;">
                        <table id="" class="table-striped table-condensed table-bordered" width="100%">
                            <thead>
                                <tr class="mySearchTr">
                                    <th style="width:8%">Voucher</th>
                                    <th style="width:13%">Date</th>
                                    <th style="width:10%">Name</th>
                                    <th style="width:20%">SurName</th>
                                    <th style="width:10%">Regn No.</th>
                                    <th style="width:10%">Mofano</th>
                                    <th style="width:10%">DOB</th>
                                    <th style="width:5%">Action</th>
                                </tr>
                            </thead>
                            <tbody class="sTbody">
                            </tbody>
                        </table>
                    </div>
                    <div class="row">
                        <div class="col-xs-12 text-right search-action-bar">
                            <input type="button" class="btn btn-primary sprev" value="Previous">
                            <input type="button" class="btn btn-primary snext" value="Next">
                        </div>
                    </div>
                </div>
                <div class="modal-footer"></div>
            </div>
        </div>
    </div>
    <?php include("includes/linksfoot.php"); ?>
</body>

</html>