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

$formname = 'Expired Member';
$maindb = 'expired';
$printfile = "job_print.php";
$file = 'expired.php';
$trandbexist = 0;
$grid = '';
$keyfld = "code";
$focusfield = "name";
$keycond = "";
$username = $_SESSION["username_" . $dbname];
$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$zroot = $_SESSION["zdbroot"];
mysqli_select_db($conn, $zdb);

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

if (isset($_POST["submit"])) {

    $a = 1;
    $qvouch = $_POST["code"];
    $accode = $_POST["accode"];
    $memcode = $_POST["memcode"];
    $name = $_POST["name"];
    $family = $_POST["family"];
    $aadhaar = $_POST["aadhaar"];
    $dob = $_POST["dob"];
    $vouchdt = $_POST["vouchdt"];

    $mvouch = $qvouch;

    if ($a == 1) {

       
        mysqli_query($conn, "update $zroot.`member` set expired = '$vouchdt' where accode = '$accode' ") or die(mysqli_error($conn));

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

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

            $mvouch = $qvouch;

            mysqli_query($conn, "INSERT INTO `$maindb`(code, `accode`, `username`, `vouchdt`, `memcode`, `name`, `aadhaar`, `dob`, `family`)
                                                VALUES('$qvouch', '$accode','$username', '$vouchdt', '$memcode', '$name', '$aadhaar', '$dob', '$family')") or die(mysqli_error($conn));
            insmess();
            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit");
        } else {
            $mvouch = $qvouch;
            mysqli_query($conn, "UPDATE `$maindb` SET `accode`='$accode', `username`='$username', `vouchdt`='$vouchdt', `memcode`='$memcode', `name`='$name', 
                                                      `aadhaar`='$aadhaar', `dob`='$dob', `family`='$family' where code = '$mvouch' ") or die(mysqli_error($conn));

            updmess();
            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit");
        }
    }
}

if ($addflag != 1) {

    $getvouch = '';
    if ($addflag == 0) {
        $getvouch = $_GET[$keyfld];
    } else {
        $getvouch = $qvouch;
    }

    $result = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE $keyfld='$getvouch' ") or die(mysqli_error($conn));
    $get = mysqli_fetch_array($result);
    $acd = $get['accode'];
}

$senable = "";
$cenable = "";

if (isset($_GET["delete"])) {
  
    mysqli_query($conn, "update $zroot.`member` set expired = '0000-00-00' where accode = '$acd' ") or die(mysqli_error($conn));
    delete($zdb, "$maindb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
}

include("includes/linkshead.php");
?>
<script src="MyScript/expired.js" type="text/javascript"></script>
<script src="MyScript/expired_search.js" type="text/javascript"></script>
</head>
<body>
    <form action='' method='POST'>
        <!-- Default box -->
        <div class="row">
            <div class="col-lg-5">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title"><?php Echo $formname; ?></h3>

                    </div>
                    <div class="panel-body">



                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Member No. Entry</label>
                            </div>
                            <div class="col-lg-2 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="hidden" class="form-control form code" name="code" value="<?php Echo ($addflag != 1) ? $get["code"] : ""; ?>" >
                                <input type="text" class="form-control form focusfield accode" name="accode" value="<?php Echo ($addflag != 1) ? $get["accode"] : ""; ?>" required>
                            </div>
                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg"></label>
                            </div>
                            <div class="col-lg-5 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="text" name="name" class="form-control form name"  value="<?php echo ($addflag != 1) ? $get["name"] : ""; ?>" >
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Family ID</label>
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="text" name="memcode" class="form-control form memcode"  value="<?php echo ($addflag != 1) ? $get["memcode"] : ""; ?>" >
                            </div>

                            <div class="col-lg-1 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg"></label>
                            </div>
                            <div class="col-lg-5 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="text" name="family" class="form-control form familyname"  value="<?php echo ($addflag != 1) ? $get["family"] : ""; ?>" >
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-lg-3 col-md-1 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Aadhaar No.</label>
                            </div>
                            <div class="col-lg-4 col-md-2 col-sm-3 col-xs-3 pad">
                                <input type="text" class="form-control form aadhaar" name="aadhaar" value="<?php Echo ($addflag != 1) ? $get["aadhaar"] : ""; ?>" >
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">DOB</label>
                            </div>
                            <div class="col-lg-3 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="date" class="form-control form dob" name="dob" value="<?php Echo ($addflag != 1) ? $get["dob"] : ""; ?>" >
                            </div>   
                        </div>
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg" style='color:red'>Expired Date</label>
                            </div>
                            <div class="col-lg-3 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="date" class="form-control form" name="vouchdt" value="<?php Echo ($addflag != 1) ? $get["vouchdt"] : date("Y-m-d"); ?>" style='color:red'>
                            </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 searchModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span>&times;</span></button>
                    <h4 class="modal-title" id="myLargeModalLabel">Search <? Echo $formname; ?></h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-lg-2">
                            <select class="form-control sfield">
                                <option value="1">Expired Date</option> 
                                <option value="2">Member No.</option>
                                <option value="3">Family ID</option> 
                                <option value="4">Aadhaar</option>
                                <option value="5">DOB</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control soperator">
                                <option value="">Type of Search</option>
                                <option value="%">Like</option>
                                <option value="=">Exactly</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control sortBy">
                                <option value="">Sort By</option> 
                                <option value="1">Expired Date</option> 
                                <option value="2">Member No.</option>
                                <option value="3">Family ID</option> 
                                <option value="4">Aadhaar</option>
                                <option value="5">DOB</option>
                            </select> 
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control orderAs">
                                <option value="desc">Desc</option>
                                <option value="asc">Asc</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <input type="text" value="" class="form-control ssearch" placeholder="Search Here">
                        </div>
                        <div class="col-lg-2">
                            <input type="button" style="border-radius: 5px" class="btn btn-primary sload" value="Search" >
                        </div>
                    </div>
                    <div class="col-lg-12 sloader text-center">
                        <!--<img src="images/search.gif" alt="loading">-->       
                    </div>
                    <div class="col-lg-12 snoRecord text-center">
                        <h3>NO RECORDS FOUND</h3>
                    </div>
                    <div class="table-responsive" style="max-height: 400px;overflow: auto;">
                        <table id="" class="table table-striped table-condensed table-bordered" width="100%">
                            <thead>
                                <tr class="mySearchTr">
                                    <th width="10%">Expired Date</th>
                                    <th width="10%">Member No.</th>
                                    <th width="10%">Family ID</th>
                                    <th width="10%">Aadhaar</th>
                                    <th width="10%">DOB</th>
                                    <th width="5%">Action</th>

                                </tr>
                            </thead>
                            <tbody class="sTbody">
                            </tbody>
                        </table>
                    </div>
                    <div class="row">
                        <div class="col-xs-12 text-right search-action-bar">
                            <input type="button" style="border-radius: 5px" class="btn btn-primary sprev" value="Previous">
                            <input type="button" style="border-radius: 5px" class="btn btn-primary snext" value="Next">
                        </div>
                    </div>

                </div>
                <div class="modal-footer"></div>
            </div>
        </div>
    </div>
    <?php include("includes/linksfoot.php"); ?>
</body>
</html>
