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

$formname = 'User Creation';
$maindb = 'usermain';
$trandb = 'usercomp';
$printfile = "";
$file = 'user.php';
$trandbexist = 0;
$grid = '';
$keyfld = "code";

$admin = $_SESSION["admin_" . $dbname];
$username = $_SESSION["username_" . $dbname];
$password = $_SESSION["password_" . $dbname];
$getuser = $_SESSION["usertype_" . $dbname];
$spectype = $_SESSION["spltype_" . $dbname];

$keycond = "and `spltype`='$spectype'";

include("includes/vouchno_generate.php");
include("includes/prev&next.php");

if (isset($_POST["submit"])) {
    $a = 1;
    $user = $_POST["username"];
    $password = $_POST["password"];
    $spltype = $_POST["spltype"];
    $usertype = $_POST["usertype"];

    ################## ENTRIES ##################

    $addnewvisa = $_POST["addnewvisa"];
    $submissionent = $_POST["submissionent"];
    $release = $_POST["release"];
    $stampdateupd = $_POST["stampdateupd"];
    $mofaent = $_POST["mofaent"];
    $pastatus = $_POST["pastatus"];
    $crm = $_POST["crm"];
    $agent = $_POST["agent"];
    $cash = $_POST["cash"];
    $bank = $_POST["bank"];
    $cashrecp = $_POST["cashrecp"];
    $bankrecp = $_POST["bankrecp"];
    $movefile = $_POST["movefile"];
    $entinvoice = $_POST["entinvoice"];
    $courin = $_POST["courin"];
    $courout = $_POST["courout"];

    ################## Reports ##################

    $visareg = $_POST["visareg"];
    $agentreg = $_POST["agentreg"];
    $submission = $_POST["submission"];
    $mofalist = $_POST["mofalist"];
    $nonsubmission = $_POST["nonsubmission"];
    $blamt = $_POST["blamt"];
    $ledger = $_POST["ledger"];
    $mofanb = $_POST["mofanb"];
    $courinreg = $_POST["courinreg"];
    $couroutreg = $_POST["couroutreg"];

    ################## Search Visa ##################

    $searchvisa = $_POST["searchvisa"];

    if (isset($_POST["name"])) {
        $result = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE `username`= '$user' AND code != '$qvouch' and `spltype`='$spectype'") or die(mysqli_error($conn));
        if (mysqli_num_rows($result) > 0) {
            $a = 0;
            browse("Name Already Exist");
            header("refresh: 1; $file?code=$qvouch&mode=last");
        }
    }

    if ($a == 1) {
        if ($addflag == 1) {
            $gen1 = mysqli_query($conn, "SELECT MAX($keyfld) AS maxcode FROM `$maindb` LIMIT 0,1 ") or die(mysqli_error($conn));

            if (mysqli_num_rows($gen1) > 0) {
                $vvouch = mysqli_fetch_assoc($gen1);
                $qvouch = $vvouch["maxcode"] + 1;
            } else {
                $qvouch = '1';
            }
            $mvouch = $qvouch;
        }

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

        mysqli_query($conn, "DELETE FROM `$trandb` WHERE `username`='$qvouch' ") or die(mysqli_error($conn));
        $count = $_POST["items"];
        for ($i = 0; $i < $count; $i++) {
            $cono = $_POST["cono_$i"];
            $finyear = $_POST["finyear_$i"];
            $yearname = $_POST["yearname_$i"];
            $startdate = $_POST["startdate_$i"];
            $lastdate = $_POST["lastdate_$i"];

            if (!empty($cono)) {
                $company = mysqli_query($conn, "SELECT `name` FROM `company` WHERE `code`='$cono'") or die(mysqli_error($conn));
                $co = mysqli_fetch_array($company);
                $cname = $co['name'];

                mysqli_query($conn, "INSERT INTO `$trandb`(`username`,`cono`,`cname`, `finyear`, `yearname`, `startdate`, `lastdate`, `spltype`) 
                    VALUES ('$qvouch', '$cono', '$cname', '$finyear', '$yearname', '$startdate', '$lastdate', '$spltype')") or die(mysqli_error($conn));
            }
        }

        ############################## MAIN  ######################################################

        if ($addflag == 1) {

            $usecode = mysqli_query($conn, "SELECT code FROM `usermain` WHERE username='$user' and `password`='$password' and `spltype`='$spltype'") or die(mysqli_error($conn));
            $getuser = mysqli_fetch_object($usecode);
            $code = $getuser->code;

            mysqli_query($conn, "INSERT INTO `$maindb`(`code`, `username`, `password`, `spltype`, `usertype`, `addnewvisa`, `submissionent`, `release`,`stampdateupd`,
                                                       `mofaent`, `pastatus`, `crm`,`agent`, `cash`, `cashrecp`, `bank`, `bankrecp`, `movefile`, `entinvoice`,`courin`, `courout`,
                                                        `visareg`,`agentreg`, `submission`, `mofalist`, `nonsubmission`, `blamt`, `ledger`, `mofanb`, `courinreg`, `couroutreg`, `searchvisa`)
                                              VALUES('$qvouch', '$user', '$password', '$spltype', '$usertype', '$addnewvisa', '$submissionent','$release', '$stampdateupd',
                                                      '$mofaent', '$pastatus', '$crm', '$agent', '$cash', '$cashrecp', '$bank', '$bankrecp', '$movefile','$entinvoice','$courin', '$courout',
                                                       '$visareg', '$agentreg', '$submission', '$mofalist', '$nonsubmission', '$blamt', '$ledger', '$mofanb','$courinreg', '$couroutreg', '$searchvisa')") or die(mysqli_error($conn));
            insmess();
            $mvouch = $qvouch;
            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit&spltype=$spectype");
        } else {
            $mvouch = $qvouch;

            $usecode = mysqli_query($conn, "SELECT code FROM `usermain` WHERE username='$user' and `password`='$password' and `spltype`='$spltype'") or die(mysqli_error($conn));
            $getuser = mysqli_fetch_object($usecode);
            $code = $getuser->code;

            mysqli_query($conn, "UPDATE `$maindb` SET  `username`='$user', `password`='$password', `usertype`='$usertype', `searchvisa`='$searchvisa',
                                                       `addnewvisa`='$addnewvisa', `submissionent`='$submissionent', `release`='$release', `stampdateupd`='$stampdateupd',  
                                                       `mofaent`='$mofaent', `pastatus`='$pastatus', `crm`='$crm', `agent`='$agent',`cash`='$cash',`cashrecp`='$cashrecp',
                                                       `bank`='$bank',`bankrecp`='$bankrecp', `movefile`='$movefile', `entinvoice`='$entinvoice',`courin`='$courin',`courout`='$courout',
                                                       `visareg`='$visareg',`agentreg`='$agentreg', `submission`='$submission', `mofalist`='$mofalist',`nonsubmission`='$nonsubmission',
                                                       `blamt`='$blamt',`ledger`='$ledger',`mofanb`='$mofanb', `courinreg`='$courinreg',
                                                       `couroutreg`='$couroutreg' WHERE code = '$mvouch' and `spltype`='$spltype' ") or die(mysqli_error($conn));
            updmess();
            //            browse($spectype); 
            header("refresh: 1; $file?$keyfld=$mvouch&spltype=$spectype&mode=edit");
        }
    }
}

if ($addflag != 1) {

    $getvouch = '';
    if ($addflag == 0) {
        $getvouch = $_GET[$keyfld];
    } else {
        $getvouch = $qvouch;
    }
    //    browse($speccond);
    $result = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE $keyfld='$getvouch' $keycond") or die(mysqli_error($conn));
    $get = mysqli_fetch_array($result);
}
$senable = "";
$cenable = "";

/* DELETE */
if (isset($_GET["delete"])) {
    delete($zdb, "$maindb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
}
?>
<?php include("includes/linkshead.php"); ?>
<style>
    input[type=checkbox] {
        width: 20px;
        height: 20px;
    }

    .fa-eye {
        position: absolute;
        top: 28%;
        right: 6%;
        cursor: pointer;
        color: black;
    }
</style>
<script src="MyScript/user.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
    $("body").on('click', '.fa-eye', function() {
        // $(this).toggleClass("fa-eye");
        var input = $(".password");
        var input2 = $(".confpass");
        if (input.attr("type") === "password") {
            input.attr("type", "text");
        } else {
            input.attr("type", "password");
        }
        if (input2.attr("type") === "password") {
            input2.attr("type", "text");
        } else {
            input2.attr("type", "password");
        }

    });
});
</script>

<body>
    <!--Default box-->
    <form action='' method='POST'>
        <!--Default box-->
        <div class="">
            <div class="col-lg-7">

                <div class="panel panel-default">

                    <div class="panel-heading">
                        <h3 class="panel-title"><?php echo $formname; ?></h3>
                        <div class="actions pull-right">
                            <i class="fa fa-chevron-down"></i>
                        </div>
                    </div>
                    <div class="panel-body">


                        <div class="row">
                            <label class="col-sm-3 control-label marg">User Name</label>
                            <div class="col-sm-6">
                                <input type="text" class="form-control form focusfield username" name="username" placeholder="User" autocomplete="off" value='<? echo ($addflag != 1) ? $get['username'] : ''; ?>' required>
                            </div>
                        </div>
                        <div class="row">
                            <label class="col-sm-3 control-label marg">Password</label>
                            <div class="col-sm-6">
                                <?php if ($getuser == 1){ ?>
                                <i class="fa fa-eye" aria-hidden="true"></i>
                                <?php } ?>
                                <input type="password" class="form-control form password" name="password" id="pass" autocomplete="off" placeholder="Password" value='<? echo ($addflag != 1) ? $get['password'] : ''; ?>' required="">
                            </div>
                        </div>
                        <div class="row">
                            <label class="col-sm-3 control-label marg">Confirm Pass</label>
                            <div class="col-sm-6">
                                <input type="password" name="confpass" id="confpass" class="form-control form confpass" placeholder="Confirm Password" required="" value='<? echo ($addflag != 1) ? $get['password'] : ''; ?>'>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-6">
                                <p id="alert"></p>
                            </div>
                        </div>
                        <div class="row">
                            <label class="col-sm-3 control-label marg">User Type</label>
                            <div class="col-sm-6">

                                <select class='form-control select2 form' name="usertype" id="usertype">
                                    <?php
                                    if ($addflag != 1) {
                                        $usertyp = "";
                                        if ($get['usertype'] == 1) {
                                            $ucode = "1";
                                            $usertyp = "Supervisor";
                                        }
                                        if ($get['usertype'] == 2) {
                                            $ucode = "2";
                                            $usertyp = "Admin";
                                        }
                                        if ($get['usertype'] == 3) {
                                            $ucode = "3";
                                            $usertyp = "Staff";
                                        }
                                        echo "<option value='$ucode'>$usertyp</option>";
                                    }
                                    ?>
                                    <option value=""></option>
                                    <option value="1">Supervisor</option>
                                    <option value="2">Admin</option>
                                    <option value="3">Staff</option>
                                </select>
                            </div>
                        </div>
                        <?php
                        if ($spectype == "1") {
                        ?>
                            <div class="row">
                                <label class="col-sm-4 control-label marg">Special</label>
                                <div class="col-sm-2" style="margin-top:6px">
                                    <input type="checkbox" class="form  spltype" id="spltype" name="spltype" value="1" <?
                                                                                                                        if ($get['spltype'] == 1) {
                                                                                                                            echo "checked";
                                                                                                                        }
                                                                                                                        ?>>
                                </div>
                            </div>
                        <?php } ?>

                        <div class="nav-tabs-custom">
                            <ul class="nav nav-tabs">
                                <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true">Entries</a></li>
                                <li class=""><a href="#tab_2" data-toggle="tab" aria-expanded="true">Reports</a></li>
                                <li class=""><a href="#tab_3" data-toggle="tab" aria-expanded="true">Search Visa</a></li>
                            </ul>
                            <div class="tab-content">
                                <div class="tab-pane active" id="tab_1">
                                    <div class="row">
                                        <label class="col-sm-6 control-label marg selectall" style="margin-bottom:5px;margin-top:5px">Select All/UnSelect All</label>
                                        <div class="col-sm-4" style="margin-bottom:5px;margin-top:3px">
                                            <input type="checkbox" class="form " id="Sentries" value="1">
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Add New Entry</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  entries" id="addnewvisa" name="addnewvisa" value="1" <?
                                                                                                                                        if ($get['addnewvisa'] == 1) {
                                                                                                                                            echo "checked";
                                                                                                                                        }
                                                                                                                                        ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Submission Update</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  entries" id="submissionent" name="submissionent" value="1" <?
                                                                                                                                            if ($get['submissionent'] == 1) {
                                                                                                                                                echo "checked";
                                                                                                                                            }
                                                                                                                                            ?>>
                                        </div>
                                    </div>

                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Release Update</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  entries" id="release" name="release" value="1" <?
                                                                                                                                if ($get['release'] == 1) {
                                                                                                                                    echo "checked";
                                                                                                                                }
                                                                                                                                ?>>
                                        </div>

                                        <label class="col-sm-4 control-label marg">Stamping Date Update</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  entries " id="stampdateupd" name="stampdateupd" value="1" <?
                                                                                                                                            if ($get['stampdateupd'] == 1) {
                                                                                                                                                echo "checked";
                                                                                                                                            }
                                                                                                                                            ?>>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg"> Mofa Update</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  entries" id="mofaent" name="mofaent" value="1" <?
                                                                                                                                if ($get['mofaent'] == 1) {
                                                                                                                                    echo "checked";
                                                                                                                                }
                                                                                                                                ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Passport Status</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  entries" id="pastatus" name="pastatus" value="1" <?
                                                                                                                                    if ($get['pastatus'] == 1) {
                                                                                                                                        echo "checked";
                                                                                                                                    }
                                                                                                                                    ?>>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">CRM</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  entries" id="crm" name="crm" value="1" <?
                                                                                                                        if ($get['crm'] == 1) {
                                                                                                                            echo "checked";
                                                                                                                        }
                                                                                                                        ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Agent</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  entries" id="agent" name="agent" value="1" <?
                                                                                                                            if ($get['agent'] == 1) {
                                                                                                                                echo "checked";
                                                                                                                            }
                                                                                                                            ?>>
                                        </div>
                                    </div>
                                    <div class="row">

                                        <label class="col-sm-4 control-label marg">Cash</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  entries" id="cash" name="cash" value="1" <?
                                                                                                                            if ($get['cash'] == 1) {
                                                                                                                                echo "checked";
                                                                                                                            }
                                                                                                                            ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Bank</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  entries" id="bank" name="bank" value="1" <?
                                                                                                                            if ($get['bank'] == 1) {
                                                                                                                                echo "checked";
                                                                                                                            }
                                                                                                                            ?>>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Cash Recp</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  entries" id="cashrecp" name="cashrecp" value="1" <?
                                                                                                                                    if ($get['cashrecp'] == 1) {
                                                                                                                                        echo "checked";
                                                                                                                                    }
                                                                                                                                    ?>>
                                        </div>

                                        <label class="col-sm-4 control-label marg">Bank Recp</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  entries" id="bankrecp" name="bankrecp" value="1" <?
                                                                                                                                    if ($get['bankrecp'] == 1) {
                                                                                                                                        echo "checked";
                                                                                                                                    }
                                                                                                                                    ?>>
                                        </div>
                                    </div>

                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Move File</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  entries" id="movefile" name="movefile" value="1" <?
                                                                                                                                    if ($get['movefile'] == 1) {
                                                                                                                                        echo "checked";
                                                                                                                                    }
                                                                                                                                    ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Invoice</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  entries" id="entinvoice" name="entinvoice" value="1" <?
                                                                                                                                        if ($get['entinvoice'] == 1) {
                                                                                                                                            echo "checked";
                                                                                                                                        }
                                                                                                                                        ?>>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Courier In</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  entries" id="courin" name="courin" value="1" <?
                                                                                                                                if ($get['courin'] == 1) {
                                                                                                                                    echo "checked";
                                                                                                                                }
                                                                                                                                ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Courier Out</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  entries" id="courout" name="courout" value="1" <?
                                                                                                                                if ($get['courout'] == 1) {
                                                                                                                                    echo "checked";
                                                                                                                                }
                                                                                                                                ?>>
                                        </div>
                                    </div>
                                </div>
                                <div class="tab-pane" id="tab_2">
                                    <div class="row">
                                        <label class="col-sm-6 control-label marg selectall" style="margin-bottom:5px;margin-top:5px">Select All/UnSelect All</label>
                                        <div class="col-sm-4" style="margin-bottom:5px;margin-top:3px">
                                            <input type="checkbox" class="form " id="Sreports" value="1">
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Visa Register</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="visareg" name="visareg" value="1" <?
                                                                                                                                if ($get['visareg'] == 1) {
                                                                                                                                    echo "checked";
                                                                                                                                }
                                                                                                                                ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Agent Register</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="agentreg" name="agentreg" value="1" <?
                                                                                                                                    if ($get['agentreg'] == 1) {
                                                                                                                                        echo "checked";
                                                                                                                                    }
                                                                                                                                    ?>>
                                        </div>
                                    </div>

                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Submission List</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="submission" name="submission" value="1" <?
                                                                                                                                        if ($get['submission'] == 1) {
                                                                                                                                            echo "checked";
                                                                                                                                        }
                                                                                                                                        ?>>
                                        </div>

                                        <label class="col-sm-4 control-label marg">Mofa List</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="mofalist" name="mofalist" value="1" <?
                                                                                                                                    if ($get['mofalist'] == 1) {
                                                                                                                                        echo "checked";
                                                                                                                                    }
                                                                                                                                    ?>>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Non Submission List</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="nonsubmission" name="nonsubmission" value="1" <?
                                                                                                                                            if ($get['nonsubmission'] == 1) {
                                                                                                                                                echo "checked";
                                                                                                                                            }
                                                                                                                                            ?>>
                                        </div>

                                        <label class="col-sm-4 control-label marg">Blank Amount</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="blamt" name="blamt" value="1" <?
                                                                                                                            if ($get['blamt'] == 1) {
                                                                                                                                echo "checked";
                                                                                                                            }
                                                                                                                            ?>>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Ledger</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="ledger" name="ledger" value="1" <?
                                                                                                                                if ($get['ledger'] == 1) {
                                                                                                                                    echo "checked";
                                                                                                                                }
                                                                                                                                ?>>
                                        </div>

                                        <label class="col-sm-4 control-label marg">Mofa Not Built</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="mofanb" name="mofanb" value="1" <?
                                                                                                                                if ($get['mofanb'] == 1) {
                                                                                                                                    echo "checked";
                                                                                                                                }
                                                                                                                                ?>>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Courier In Register</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="courinreg" name="courinreg" value="1" <?
                                                                                                                                    if ($get['courinreg'] == 1) {
                                                                                                                                        echo "checked";
                                                                                                                                    }
                                                                                                                                    ?>>
                                        </div>

                                        <label class="col-sm-4 control-label marg">Courier Out Register</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="courinreg" name="courinreg" value="1" <?
                                                                                                                                    if ($get['courinreg'] == 1) {
                                                                                                                                        echo "checked";
                                                                                                                                    }
                                                                                                                                    ?>>
                                        </div>
                                    </div>
                                </div>
                                <div class="tab-pane" id="tab_3">
                                    <div class="row">
                                        <label class="col-sm-6 control-label marg selectall" style="margin-bottom:5px;margin-top:5px">Select All/UnSelect All</label>
                                        <div class="col-sm-4" style="margin-bottom:5px;margin-top:3px">
                                            <input type="checkbox" class="form " id="Ssearchvisa" value="1">
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Search Visa</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  search" id="searchvisa" name="searchvisa" value="1" <?
                                                                                                                                    if ($get['searchvisa'] == 1) {
                                                                                                                                        echo "checked";
                                                                                                                                    }
                                                                                                                                    ?>>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="panel-body">
                                <div class="table-responsive">
                                    <table class="table table-striped table-condensed table-bordered" width="100%">
                                        <thead class="mySearchTr">
                                            <tr>
                                                <th width="3%"></th>
                                                <th width="17%">Company</th>
                                                <th width="10%">Year</th>
                                                <th width="10%">Name</th>
                                                <th width="10%">From</th>
                                                <th width="10%">To</th>
                                            </tr>
                                        </thead>
                                        <tbody class="tbody">
                                            <?php
                                            if ($addflag != 1) {
                                                $ctr = 0;
                                                $gettran = mysqli_query($conn, "SELECT `cono`,`cname`,`finyear`,`startdate`,`lastdate`,`yearname` FROM `usercomp` WHERE `username`='$get[code]' ORDER BY `cono`") or die(mysqli_error($conn));
                                                while ($tran = mysqli_fetch_array($gettran)) {
                                                    $fetcomp = mysqli_query($conn, "SELECT `code`,`name` FROM `company` WHERE `code`='$tran[cono]'") or die(mysqli_error($conn));
                                                    $fcomp = mysqli_fetch_array($fetcomp);

                                                    $fetyear = mysqli_query($conn, "SELECT `finyear` FROM `compyear` WHERE `finyear`='$tran[finyear]'") or die(mysqli_error($conn));
                                                    $fyear = mysqli_fetch_array($fetyear);

                                                    echo "<tr>";
                                                    echo "<td><i class='fa fa-close remove' style='display:none;'></i></td>";
                                                    echo "<td>";
                                                    echo "<select class='form-control form cono select2' name='cono_$ctr' style='width:100%'>";
                                                    echo "<option value='$fcomp[code]'>$fcomp[name]</option>";
                                                    $gcomp = mysqli_query($conn, "SELECT `code`,`name` FROM `company` where code !='' $speccond") or die(mysqli_error($conn));
                                                    while ($comp = mysqli_fetch_array($gcomp)) {
                                                        echo "<option value='$comp[code]'>$comp[name]</option>";
                                                    }
                                                    echo "</select>";
                                                    echo "</td>";
                                                    echo "<td>";
                                                    echo "<select class='form-control form finyear select2' name='finyear_$ctr' style='width:100%'>";
                                                    echo "<option value='$fyear[finyear]'>$fyear[finyear]</option>";

                                                    $gyear = mysqli_query($conn, "SELECT `finyear` FROM `compyear` where finyear != '' group by finyear") or die(mysqli_error($conn));
                                                    while ($year = mysqli_fetch_array($gyear)) {
                                                        echo "<option value='$year[finyear]'>$year[finyear]</option>";
                                                    }
                                                    echo "</select>";
                                                    echo "</td>";
                                                    echo "<td><input type='text' class='form-control form yearname' name='yearname_$ctr' value='$tran[yearname]' readonly></td>";
                                                    echo "<td><input type='text' class='form-control form startdate' name='startdate_$ctr' value='$tran[startdate]' readonly></td>";
                                                    echo "<td><input type='text' class='form-control form lastdate' name='lastdate_$ctr' value='$tran[lastdate]' readonly></td>";
                                                    echo "</tr >";
                                                    $ctr++;
                                                }
                                            } else {
                                            ?>
                                                <tr>
                                                    <td><i class='fa fa-close remove'></i></td>
                                                    <td>
                                                        <select class="form-control form cono select2" name="cono_0" style='width:100%' required>
                                                            <option value=""></option>
                                                            <?php
                                                            $gcomp = mysqli_query($conn, "SELECT `code`,`name` FROM `company` where code !='' $speccond") or die(mysqli_error($conn));

                                                            while ($comp = mysqli_fetch_array($gcomp)) {
                                                                echo "<option value='$comp[code]'>$comp[name]</option>";
                                                            }
                                                            ?>
                                                        </select>
                                                    </td>
                                                    <td>
                                                        <select class="form-control form finyear select2" name="finyear_0" style='width:100%' required>
                                                            <option value=""></option>
                                                            <?php
                                                            $gyear = mysqli_query($conn, "SELECT `finyear` FROM `compyear` group by finyear") or die(mysqli_error($conn));
                                                            while ($year = mysqli_fetch_array($gyear)) {
                                                                echo "<option value='$year[finyear]'>$year[finyear]</option>";
                                                            }
                                                            ?>
                                                        </select>
                                                    </td>
                                                    <td><input type="text" class="form-control form yearname" name="yearname_0" value="" readonly></td>
                                                    <td><input type="text" class="form-control form startdate" name="startdate_0" value="" readonly></td>
                                                    <td><input type="text" class="form-control form lastdate" name="lastdate_0" value="" readonly></td>
                                                </tr>
                                            <?
                                            }
                                            ?>
                                        </tbody>
                                    </table>
                                </div>
                                <div class="col-lg-12 pad">
                                    <button type="button" class="btn btn-primary btn-square form" id="addnew">
                                        <i class="fa fa-plus" data-toggle='tooltip' title='Add Row'></i>
                                    </button>
                                    <input type="hidden" id="items" name="items" value="<?php echo ($addflag != 1) ? $ctr : 1; ?>" />
                                </div>
                            </div>

                        </div>
                    </div>
                    <div class="panel-footer">
                        <?php include("includes/buttons.php"); ?>
                    </div>
                </div>
            </div>

        </div>
    </form>
    <div class="modal fade bs-example-modal-lg" 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=" table-responsive">
                        <table id="example1" class="table table-striped">
                            <thead>
                                <tr class="mySearchTr">
                                    <th>code</th>
                                    <th>Name</th>
                                    <th>Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                if ($addflag != 1) {
                                    $srchresult = mysqli_query($conn, "SELECT * FROM `$maindb` where code!='' $keycond") or die(mysqli_error($conn));
                                    while ($row = mysqli_fetch_array($srchresult)) {
                                        echo "<tr>";
                                        echo "<td align='left'>$row[code]</td>";
                                        echo "<td align='left'>$row[username]</td>";
                                        echo "<td align='left'><a href=\"$file?mode=edit&$keyfld=$row[$keyfld]\"><i class='fa fa-pencil' style='font-size:1.3em;color:#00C0EF;cursor:pointer;'></i></a></td>";
                                        echo "</tr>";
                                    }
                                }
                                ?>
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="modal-footer"></div>
            </div>
        </div>
    </div>
</body>

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