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

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

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

//browse($spectype);
if ($spectype == "1") {
    $speccond = "and `compchng`='1'";
} else {
    $speccond = "and `compchng`=''";
}

$keycond = "and `spltype`='$spectype'";
//browse($spectype);

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

if (isset($_POST["submit"])) {
    $a = 1;
    $user = $_POST["user"];
    $password = $_POST["password"];
    $usertype = $_POST["usertype"];
    $admin = $_POST["admin"];
    $spltype = $_POST["spltype"];
    $ipadd = $_POST["ipadd"];
    $series = $_POST["series"];
    $loginpin = $_POST["loginpin1"] . $_POST["loginpin2"] . $_POST["loginpin3"] . $_POST["loginpin4"];
    ################## MASTERS ##################
    $customer = $_POST["customer"];
    $itemgrp = $_POST["itemgrp"];
    $item = $_POST["item"];
    $delvcomp = $_POST["delvcomp"];
    $paytype = $_POST["paytype"];
    $tablemast = $_POST["tablemast"];

    ################### TRANSACTION ##################
    $kotent = $_POST["kotent"];
    $kotpent = $_POST["kotpent"];
    $bill = $_POST["bill"];
    $tabletrans = $_POST["tabletrans"];

    ################### REPORTS ##################
    $salereg = $_POST["salereg"];
    $dailyrep = $_POST["dailyrep"];
    $online = $_POST["online"];
    $bestofd = $_POST["bestofd"];
    $saleitem = $_POST["saleitem"];
    $saletable = $_POST["saletable"];
    $cardsum = $_POST["cardsum"];
    $salegrp = $_POST["salegrp"];
    $discsale = $_POST["discsale"];

    ################## TOOLS ##################
    $tlcompany = $_POST["compsetup"];
    $tlbackup = $_POST["backup"];
    $tlprofile = $_POST["profile"];
    $dstock = $_POST["dstock"];

    $count = $_POST["items"];


    if (isset($_POST["name"])) {
        $result = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE `user`= '$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));

        for ($i = 0; $i < $count; $i++) {
            $cono = $_POST["cono_$i"];
//            $cname = $_POST["cname_$i"];
            $finyear = $_POST["finyear_$i"];
            $yearname = $_POST["yearname_$i"];
            $startdate = $_POST["startdate_$i"];
            $lastdate = $_POST["lastdate_$i"];

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

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

        if ($addflag == 1) {

            $usecode = mysqli_query($conn, "SELECT code FROM `passmain` WHERE user='$username' 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`, `user`, `password`, `admin`, `ipadd`, `spltype`, `usertype`,
                                                       `customer`, `itemgrp`, `item`, `delvcomp`, `paytype`, `tablemast`,
                                                       `kotent`, `kotpent`, `bill`, `tabletrans`,
                                                       `salereg`, `dailyrep`, `online`, `bestofd`, `saleitem`, `saletable`, `cardsum`, `salegrp`, `discsale`)
                                               VALUES('$qvouch', '$user', '$password','$admin', '$ipadd', '$spltype', '$usertype',
                                                       '$customer', '$itemgrp', '$item', '$delvcomp', '$paytype', '$tablemast',
                                                       '$kotent', '$kotpent', '$bill', '$tabletrans',
                                                       '$salereg', '$dailyrep', '$online', '$bestofd', '$saleitem', '$saletable', '$cardsum', '$salegrp', '$discsale')") 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 `passmain` WHERE user='$username' 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  `user`='$user', `password`='$password',`admin`='$admin', `usertype`='$usertype', `ipadd`='$ipadd',
                                                       `customer`='$customer', `itemgrp`='$itemgrp', `item`='$item', `delvcomp`='$delvcomp',
                                                       `paytype`='$paytype', `tablemast`='$tablemast',
                                                       `kotent`='$kotent', `kotpent`='$kotpent', `bill`='$bill', `tabletrans`='$tabletrans',
                                                       `salereg`='$salereg', `dailyrep`='$dailyrep', `online`='$online', `bestofd`='$bestofd',
                                                       `saleitem`='$saleitem', `saletable`='$saletable', `cardsum`='$cardsum', `salegrp`='$salegrp', `discsale`='$discsale'
                                                       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", $conn);
}
?>
<?php include("includes/linkshead.php"); ?>
<style>
    input[type = checkbox]{
        width: 20px;
        height: 20px;

    }
    /*    .getcolor{
                    border-radius: 0px;
                    border-top: 0px;
                    border-left: 0px;
                    border-right: 0px;
            border-bottom: 1px solid;
            color: black;
        }*/
</style>
<script src="MyScript/user.js" type="text/javascript"></script>
<body>
    <!-- Default box -->
    <form action='' method='POST'>
        <!-- Default box -->
        <div class="">
            <div class="col-lg-6">
                <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 user" id="user" name="user" placeholder="User Name" autocomplete="off" value='<?php echo ($addflag != 1) ? $get['user'] : ""; ?>' required autofocus>
                            </div>
                        </div>
                        <div class="row">
                            <label class="col-sm-3 control-label marg">Password</label>
                            <div class="col-sm-6">
                                <input type="password" class="form-control form" name="password" id="pass" autocomplete="off" placeholder="Password" value='<?php 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"  placeholder="Cofirm Password" required="" value='<?php 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='usertype form-control select2 form' name="usertype" id="usertype">                                    
                                    <?php
                                    if ($addflag != 1) {
                                        $usertyp = "";
                                        if ($get['usertype'] == 'N') {
                                            $ucode = "N";
                                            $usertyp = "Normal";
                                        }
                                        if ($get['usertype'] == 'K') {
                                            $ucode = "K";
                                            $usertyp = "Kitchen";
                                        }
                                        if ($get['usertype'] == 'W') {
                                            $ucode = "W";
                                            $usertyp = "Waiter";
                                        }
                                        echo "<option value='$ucode'>$usertyp</option>";
                                    }
                                    ?>
                                    <option value=""></option>
                                    <option value="N">Normal</option>
                                    <option value="K">Kitchen</option>
                                    <option value="W">Waiter</option>
                                </select>
                            </div>
                        </div>
                        <br>
                        <div class="row" id="readmin" style="background-color: #CE79B0; margin-left: 0px; margin-right: 5px">
                            <label class="col-sm-3 control-label marg" style="color: white">Admin</label>

                            <div class="col-sm-2">
                                <input  style="height: 25px;width: 25px;" type="checkbox" class="form  admin" id="admin" name="admin" value="1" <?
                                if ($get['admin'] == 1) {
                                    Echo "checked";
                                }
                                ?>>
                            </div>
                        </div>
                        <br>
                        <!--                        <div class="row">
                                                    <label class="col-sm-3 control-label marg">IP Address</label>
                                                    <div class="col-sm-3" style="">
                                                        <input type="text" class="form-control form  ipadd" id="ipadd" name="ipadd" value="<?php echo ($addflag != 1) ? $get["ipadd"] : ""; ?>">
                                                    </div>
                                                </div>-->
                        <div class="nav-tabs-custom" id="navtab">
                            <ul class="nav nav-tabs">
                                <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true">Masters</a></li>
                                <li class=""><a href="#tab_2" data-toggle="tab" aria-expanded="false">Transaction</a></li>
                                <li class=""><a href="#tab_3" data-toggle="tab" aria-expanded="false">Reports</a></li>
                                <!--<li class=""><a href="#tab_4" data-toggle="tab" aria-expanded="false">Tools & DashBoard</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">Select All/UnSelect All</label>
                                        <div class="col-sm-1" style="margin-top:6px">
                                            <input type="checkbox" class="form " id="Smasters" value="1">
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Customer</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  masters" id="customer" name="customer" value="1" <?
                                            if ($get[customer] == 1) {
                                                echo "checked";
                                            }
                                            ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Item Group</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  masters" id="itemgrp" name="itemgrp" value="1" <?
                                            if ($get[itemgrp] == 1) {
                                                echo "checked";
                                            }
                                            ?>>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Item</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  masters" id="item" name="item" value="1" <?
                                            if ($get[item] == 1) {
                                                echo "checked";
                                            }
                                            ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Delivery Company</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  masters" id="delvcomp" name="delvcomp" value="1" <?
                                            if ($get[delvcomp] == 1) {
                                                echo "checked";
                                            }
                                            ?>>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Payment Type</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  masters" id="paytype" name="paytype" value="1" <?
                                            if ($get[paytype] == 1) {
                                                echo "checked";
                                            }
                                            ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Table Master</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  masters" id="tablemast" name="tablemast" value="1" <?
                                            if ($get[tablemast] == 1) {
                                                echo "checked";
                                            }
                                            ?>>
                                        </div>
                                    </div>
                                </div><!-- /.tab-pane -->
                                <div class="tab-pane" id="tab_2">
                                    <div class="row">
                                        <label class="col-sm-6 control-label marg selectall">Select All/UnSelect All</label>
                                        <div class="col-sm-4" style="margin-top:6px">
                                            <input type="checkbox" class="form " id="Stransactions" value="1">
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">K.O.T</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  transactions" id="kotent" name="kotent" value="1" <?
                                            if ($get[kotent] == 1) {
                                                echo "checked";
                                            }
                                            ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">K.O.T Parcel</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  transactions" id="kotpent" name="kotpent" value="1" <?
                                            if ($get[kotpent] == 1) {
                                                echo "checked";
                                            }
                                            ?>>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Billing</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  transactions" id="bill" name="bill" value="1" <?
                                            if ($get[bill] == 1) {
                                                echo "checked";
                                            }
                                            ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Table Transfer</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  transactions" id="tabletrans" name="tabletrans" value="1" <?
                                            if ($get[tabletrans] == 1) {
                                                echo "checked";
                                            }
                                            ?>>
                                        </div>
                                    </div>
                                </div><!-- /.tab-pane -->
                                <div class="tab-pane" id="tab_3">
                                    <div class="row">
                                        <label class="col-sm-6 control-label marg selectall">Select All/UnSelect All</label>
                                        <div class="col-sm-4" style="margin-top:6px">
                                            <input type="checkbox" class="form " id="Sreports" value="1">
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Sale Register</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="salereg" name="salereg" value="1" <?
                                            if ($get[salereg] == 1) {
                                                echo "checked";
                                            }
                                            ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Daily Report</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="dailyrep" name="dailyrep" value="1" <?
                                            if ($get[dailyrep] == 1) {
                                                echo "checked";
                                            }
                                            ?>>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Online</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="online" name="online" value="1" <?
                                            if ($get[online] == 1) {
                                                echo "checked";
                                            }
                                            ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Best OFD</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="bestofd" name="bestofd" value="1" <?
                                            if ($get[bestofd] == 1) {
                                                echo "checked";
                                            }
                                            ?>>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Sale Itemwise</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="saleitem" name="saleitem" value="1" <?
                                            if ($get[saleitem] == 1) {
                                                echo "checked";
                                            }
                                            ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Sale Table</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="saletable" name="saletable" value="1" <?
                                            if ($get[saletable] == 1) {
                                                echo "checked";
                                            }
                                            ?>>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Sale Groupwise</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="salegrp" name="salegrp" value="1" <?
                                            if ($get[salegrp] == 1) {
                                                echo "checked";
                                            }
                                            ?>>
                                        </div>
                                        <label class="col-sm-4 control-label marg">Cardwise Summary</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="cardsum" name="cardsum" value="1" <?
                                            if ($get[cardsum] == 1) {
                                                echo "checked";
                                            }
                                            ?>>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <label class="col-sm-4 control-label marg">Discount Sale</label>
                                        <div class="col-sm-2" style="margin-top:6px">
                                            <input type="checkbox" class="form  reports" id="discsale" name="discsale" value="1" <?
                                            if ($get[discsale] == 1) {
                                                echo "checked";
                                            }
                                            ?>>
                                        </div>
                                    </div>
                                </div><!-- /.tab-pane -->

                                <!--                                <div class="tab-pane" id="tab_4">
                                                                    <div class="row">
                                                                        <label class="col-sm-6 control-label marg selectall">Select All/UnSelect All</label>
                                                                        <div class="col-sm-4" style="margin-top:6px">
                                                                            <input type="checkbox" class="form " id="Stools" value="1">
                                                                        </div>
                                                                    </div>
                                                                    <div class="row">
                                                                        <label class="col-sm-4 control-label marg">Company Setup</label>
                                                                        <div class="col-sm-2" style="margin-top:6px">
                                                                            <input type="checkbox" class="form  tools" id="compsetup" name="compsetup" value="1" <?
                                if ($get[compsetup] == 1) {
                                    Echo "checked";
                                }
                                ?>>
                                                                        </div>
                                                                        <label class="col-sm-4 control-label marg">Backup</label>
                                                                        <div class="col-sm-2" style="margin-top:6px">
                                                                            <input type="checkbox" class="form  tools" id="backup" name="backup" value="1" <?
                                if ($get[backup] == 1) {
                                    Echo "checked";
                                }
                                ?>>
                                                                        </div>
                                                                    </div>
                                                                    <div class="row">
                                                                        <label class="col-sm-4 control-label marg">Profile</label>
                                                                        <div class="col-sm-2" style="margin-top:6px">
                                                                            <input type="checkbox" class="form  tools" id="profile" name="profile" value="1" <?
                                if ($get[profile] == 1) {
                                    Echo "checked";
                                }
                                ?>>
                                                                        </div>
                                                                    </div>
                                                                </div> -->
                            </div><!-- /.tab-content -->
                        </div>
                    </div>
                    <div class="panel-footer">
                        <?php include("includes/buttons.php"); ?>
                    </div>
                </div>
            </div>
            <div class="col-lg-6 col-md-12 col-sm-12 col-xs-12 pad" id="yeardtl">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">Year Details</h3>
                        <div class="actions pull-right">
                            <i class="fa fa-chevron-down"></i>
                        </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="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`,`finyear`,`startdate`,`lastdate`,`yearname` FROM `usercomp` WHERE `username`='$get[code]' ORDER BY `cono`")or die(mysqli_error($conn));
                                        while ($tran = mysqli_fetch_array($gettran)) {

                                            $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 finyear select2' name='finyear_$ctr' style='width:100%'>";
                                            Echo "<option value='$fyear[finyear]'>$fyear[finyear]</option>";

                                            $gyear = mysqli_query($conn, "SELECT `finyear` FROM `compyear`")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 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>
    </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[user]</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"); ?>