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

$maindb = "leadenq";
//$trandb = "saletran";
$formname = "Postponed Record Register";
$file = "postreg.php";

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
$usertype = $_SESSION["usertype"];
$zroot = $_SESSION["zdir"];

mysqli_select_db($conn,$zdb);

if (isset($_POST["view"])) {
$name = $_POST[name];
$gtype = $_POST[gtype];


$staffcond = "";
$mtypecond = "";
//    browse($gtype);
if (!empty($name)) {
$staffcond = " AND `username`='$name' ";
}

if (!empty($gtype)) {
$mtypecond = " AND `status`='$gtype' ";
}




if (empty($_POST["frmdt"])) {
browse("From Date Cannot Be Empty");
header("refresh:1; leadreg.php");
}
if (empty($_POST["todt"])) {
browse("To Date Cannot Be Empty");
header("refresh:1; leadreg.php");
}
$mfrmdate = trim($_POST["frmdt"]);
$mtodate = trim($_POST["todt"]);



// print "SELECT * FROM `$maindb` WHERE `vouchno`!='' $partyname $broker $transpor $item $godown $mtype";
$getpmain = mysqli_query($conn,"SELECT *,DATE_FORMAT(`vouchdt`, '%d-%m-%Y') as mydt,DATE_FORMAT(`deptdate`, '%d-%m-%Y') as deptdate,
                         DATE_FORMAT(`postdate`, '%d-%m-%Y') as postdate, DATE_FORMAT(`remddate`, '%d-%m-%Y') as remddate
                         FROM $maindb where `status`='Postponed' and `vouchdt` >= '$mfrmdate' AND `vouchdt` <= '$mtodate'
                         $staffcond $mtypecond order by vouchno")or die(mysqli_error($conn));

include("includes/linkshead.php");
?>
<script src="MyScript/item.js" type="text/javascript"></script>    
</head>
<body>
    <div class="" style="width:100%;">
        <div class="">
            <!--                <div class="col-lg-6">
                                <label class="label-control marg">Date - </label>
                                <label class="label-control marg"><?php // Echo Date("d-m-Y");  ?></label>
                            </div>-->

            <div class="col-lg-5">
                <label class="label-control marg">Print - </label>
                <label class="label-control marg"><?php Echo $formname; ?></label>
            </div>

            <div class="col-lg-3" style="float: right; margin-top: 5px;">
                <a onclick="window.close()" class="btn btn-primary">GO Back</a>
            </div>
        </div>
        <div class="">
            <div class="">
                <table style="width:100%;background: white" class="table-condensed table-hover table-bordered">
                    <thead>
                        <tr style="height:10px;background-color: #64CCFC;" class="">
                            <th style="width:5%;">Sr</th>
                            <?php 
                            if($usertype == 1){ ?>
                                <th style="width:10%">Staff</th>
                                <?php } ?>
                            
                            <th style="width:3%">Book No</th>
                            <th style="width:7%">Enq Date</th>
                            <th style="width:10%">Name</th>
                            <th style="width:10%">Last Name</th>
                            <th style="width:10%">Destination</th>
                            <th style="width:7%">Travel Date</th>
                            <th style="width:7%">Mobile</th>
                            <th style="width:7%">Email Id.</th>
                            <th style="width:8%">Postponed Date</th>
                            <th style="width:10%">Reminder Date</th>
                            <th style="width:10%">Remark</th>
                            <th style="width:10%">New Remark</th>                            
                            
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $ctr = 0;

                        while ($pmain = mysqli_fetch_array($getpmain)) {
                        $ctr++;
//                        browse($pmain[remddate]);
                        Echo "<tr>";
                        Echo "<td style=''>$ctr</td>"; 
                        if($usertype == 1){
                        Echo "<td style=''>$pmain[username]</td>";
                        }
                        Echo "<td style=''>$pmain[vouchno]</td>";
                        Echo "<td style=''>$pmain[mydt]</td>";
                        Echo "<td style=''>$pmain[name]</td>";
                        Echo "<td style=''>$pmain[lastname]</td>";
                        Echo "<td style=''>$pmain[destination]</td>";
                        Echo "<td style=''>$pmain[deptdate]</td>";
                        Echo "<td style=''>$pmain[mobile]</td>";
                        Echo "<td style=''>$pmain[email]</td>";
                        Echo "<td style=''>$pmain[postdate]</td>";
                        Echo "<td style=''>$pmain[remddate]</td>";
                        Echo "<td style=''>$mqty[remarks]</td>";
                        Echo "<td style=''>$pmain[remarks1]</td>";
                        Echo "</tr>";
                        }

//                            
                        ?>
                    </tbody> 
                </table>
            </div>
        </div>
    </div>

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

if (isset($_POST["excel"])) {
$name = $_POST[name];
$gtype = $_POST[gtype];


$staffcond = "";
$mtypecond = "";
//    browse($gtype);
if (!empty($name)) {
$staffcond = " AND `username`='$name' ";
}


if (empty($_POST["frmdt"])) {
browse("From Date Cannot Be Empty");
header("refresh:1; leadreg.php");
}
if (empty($_POST["todt"])) {
browse("To Date Cannot Be Empty");
header("refresh:1; leadreg.php");
}
$mfrmdate = trim($_POST["frmdt"]);
$mtodate = trim($_POST["todt"]);



// print "SELECT * FROM `$maindb` WHERE `vouchno`!='' $partyname $broker $transpor $item $godown $mtype";
$getpmain = mysqli_query($conn,"SELECT *,DATE_FORMAT(`vouchdt`, '%d-%m-%Y') as mydt FROM $maindb where `status`='Postponed' and `vouchdt` >= '$mfrmdate' AND `vouchdt` <= '$mtodate'
             $staffcond $mtypecond")or die(mysqli_error($conn));
if ($usertype == 1){
    $contents.="Sr,Staff,Book No ,Enq Date,Name,Last Name,Destination,Travel Date,Mobile,Email Id,Postponed,Reminder Date,Remark,New Remark\n";
    $contents.="\n";
}else{
    $contents.="Sr,Book No ,Enq Date,Name,Last Name,Destination,Travel Date,Mobile,Email Id,Postponed,Reminder Date,Remark,New Remark\n";
    $contents.="\n";
}
    



$ctr = 0;


while ($pmain = mysqli_fetch_array($getpmain)) {


$ctr++;

$exctr = $ctr;
$exuser = $pmain[username];
$exvouchno = $pmain[vouchno];
$exvouchdt = $pmain[vouchdt];
$exname = $pmain[name];
$exlastname = $pmain[lastname];
$exdestination = $pmain[destination];
$exdeptdate = $pmain[deptdate];
$exmobile  = $pmain[mobile];
$exemail = $pmain[email];
$exstatus = $pmain[postdate];
$exquotvisa = $pmain[remddate];
$exremarks = $mqty[remarks];
$exremarks1 = $pmain[remarks1];

$contents.=$exctr . ",";
if($usertype == 1){
    $contents.=$exuser . ",";
}
$contents.=$exvouchno . ",";
$contents.=$exvouchdt . ",";
$contents.=$exname . ",";
$contents.=$exlastname . ",";
$contents.=$exdestination. ",";
$contents.=$exdeptdate . ",";
$contents.=$exmobile . ",";
$contents.=$exemail . ",";
$contents.=$exstatus . ",";
$contents.=$exquotvisa . ",";
$contents.=$exremarks . ",";
$contents.=$exremarks1 . "\n";

}


$contents = strip_tags($contents);

//if ($_POST["dtype"] == 1) {
header("Content-Disposition: attachment; filename=$formname" . "_Summary" . date('d-m-Y') . ".csv");
print $contents;
//}
}
?>

