<?php 
session_start();
ob_start();
error_reporting(0);
include("../../pidbco/pidbjoin.php");
$sujpath="./";
if((!isset($_SESSION['user_name'])) && ($_SESSION['user_name'] == '')){
	header("Location: ../index.php");
} 
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Projects</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>font-awesome/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>font-awesome/ionicons.min.css">
    <!-- DataTables -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>plugins/datatables/dataTables.bootstrap.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>dist/css/skins/_all-skins.min.css">
    <link rel="stylesheet" type="text/css" href="tcal.css" />    
    <script type="text/javascript" src="tcal.js"></script>
<script>
function branch_change(str)
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("rbranch").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","ajaxmarket.php?comp_idd="+str,true);
xmlhttp.send();
}


        function domain_register()
    	{
		  var domstart = $('#domstart').val();
		  var domend = $('#domend').val();
		  var domsort = $('#domsort').val();
		  
		  if(domstart == ''){
		     alert("Enter Start Date");
		  } else if(domend == ''){
		     alert("Enter End Date ");
		  } else {
    		$.ajax({
			type: "POST",
			url: "ajaxmarket.php",
			data: {
			btn_edit_market: 1
			},
			cache: true,
			success: function(res)
			{
			    window.location.href="domain_expiry.php?start="+domstart+"&end="+domend+"&sort="+domsort;
			}  
			});
			}
    	 }
</script>
    
  </head>
  <body class="hold-transition skin-blue sidebar-mini">
     <div class="wrapper">
  <?php include("head.php");
        include("left.php"); ?> 
	 
      <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper" >
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1 style=" font-size: 22px;"> Domain Expiry
          	<small>- Control panel</small>
          	</h1>
          <ol class="breadcrumb">
            <li><a href="dash_board.php"><i class="fa fa-dashboard"></i> Home</a></li>
            <li class="active">Domain Expiry</li> 
          </ol>
        </section>
  <!-- Main content -->
        <section class="content" >
          <div class="row" >
            <div class="col-xs-12" >


  
  <div class="row" style=" margin-top: 20px;">	
<div class="col-md-12" style="" >
	


<div class="col-md-3"  style=" padding-left: 2px; padding-right: 0px; ">					
<div class="form-group">
	<input type="text" name="domstart" id="domstart" class="form-control tcal" placeholder="Start Date"/>
</div></div>

<div class="col-md-3"  style=" padding-left: 2px; padding-right: 0px; ">					
<div class="form-group">
	<input type="text" name="domend" id="domend" class="form-control tcal" placeholder="End Date"/>
</div></div>

<div class="col-md-3"  style=" padding-left: 2px; padding-right: 0px; ">					
<div class="form-group">
	<select name="domsort" id="domsort" class="form-control">
		<option value="">Sort By</option>
		<option value="Expiry">Expiry Date</option>
		<option value="Domain">Domain Name</option>
		<option value="Reg">Reg Date</option>
	</select>
	
</div></div>	

<div class="col-md-2"  style=" padding-left: 2px; padding-right: 0px; ">					
<div class="form-group">
	<input type="submit" class="btn btn-primary" name="frasubmit" id="frasubmit" value="Submit" onClick="domain_register();" style=" float: left; margin-left: 10px; " />	
</div></div>
</div></div>



  
  
<div id="marketingdiv123" >


<div class="box" >
   <div class="box-body" >
        <div class="box-body table-responsive no-padding" >
		 <div style=" float: right;" id="sales_reg_print">
	<?php
    
    $start   = strip_tags($_GET['start']);
    $end     = strip_tags($_GET['end']);
    $sort    = strip_tags($_GET['sort']);    
	?>
  	 
<a href="domain_exp_print.php?start=<?php echo base64_encode($start); ?>&end=<?php echo base64_encode($end); ?>&sort=<?php echo base64_encode($sort); ?>" target="_blank"><span class="fa fa-print" style="font-size:14px;"></span> Print</a></div>               	
<table id="example1" class="table table-bordered table-striped" >
<thead >
<tr >
<th>#</th>                    	
<th>Domain Name</th>
<th>Contact Person</th>
<th>Mobile</th>
<th>Email</th>
<th>Reg Date</th>
<th>Expiry Date</th>
<th>Status</th>
</tr>
</thead>
<tbody>

<?php
    $start  = strip_tags($_GET['start']);
    $end = strip_tags($_GET['end']);
    $sort = strip_tags($_GET['sort']);
	

	if($start != ''){
		
	if(($start != '') && ($end != '')){
		$dom1 = " `d_renewel` > '$start'";
	}	
		
	if($sort == 'Expiry'){
		$sort1 = "ORDER BY `d_renewel` DESC ";
	} else if($sort == 'Domain'){
		$sort1 = "ORDER BY `d_domain` DESC ";
	} else if($sort == 'Reg'){
		$sort1 = "ORDER BY `d_regdate` DESC ";	
	} else {
		$sort1 = "ORDER BY `did` DESC ";	
	}
	
	$sq = mysqli_query($con, "SELECT * FROM `p_domain` WHERE $dom1 $sort1 ");
	$k=1;
	while($rs = mysqli_fetch_array($sq)){
      $dorder = $rs['dorder'];
	  $dcust = $rs['dcust'];	
	  if($sort != 'Expiry'){		
      $dat = date('Y/m/d');
      $d_renewel = $rs['d_renewel'];
      $datetime1 = new DateTime($d_renewel);
      $datetime2 = new DateTime($dat);
      $interval = $datetime1->diff($datetime2);
      $days_between = $interval->format('%a');
	  } 
	    $sq1 = mysqli_query($con, "SELECT ocustm FROM `p_orders` WHERE `order_id`='$dorder' ");
		$rs1 = mysqli_fetch_array($sq1);
		$ocustm = $rs1['ocustm'];
		
		$sq2 = mysqli_query($con, "SELECT cname,cmob,cemail FROM `p_customers` WHERE `cidentity`='$dcust' ");
		$rs2 = mysqli_fetch_array($sq2);
		
	$d_regdate2 = $rs['d_regdate'];
	$exp = explode("/",$d_regdate2);
	$yearr =  substr($exp[0], 2, 4);
	$d_regdate = $exp[2].'/'.$exp[1].'/'.$yearr; 
	
    $d_renewel2 = $rs['d_renewel'];
	$exp = explode("/",$d_renewel2);
	$yearr2 =  substr($exp[0], 2, 4);
	$d_renewel = $exp[2].'/'.$exp[1].'/'.$yearr2;	
	?>
   <tr>
   	<td><?php echo $k; ?></td>
   	<td><?php echo $rs['d_domain']; ?></td>
   	<td><?php echo $rs2['cname']; ?></td>
   	<td><?php echo $rs2['cmob']; ?></td>
   	<td><?php echo $rs2['cemail']; ?></td>
    <td><?php echo $d_regdate; ?></td>
   	<td><?php echo $d_renewel; ?></td>
   	<td><?php if($days_between <= 30){ echo "R"; } else if($rs['d_renewel'] < $dat){ echo "E"; } else { echo "L"; } ?></td>
   </tr>
   <?php $k=$k+1; } } ?>
   
</tbody>
</table>
         		  </div>
                </div><!-- /.box-body -->
              </div><!-- /.box -->
	
	
</div>
	
		
			
			
			








                           
            </div><!-- /.col -->
          </div><!-- /.row -->
        </section><!-- /.content -->
  </div><!-- /.content-wrapper -->
  </div>
	<!-- <?php include("footer.php"); ?> -->
 <!-- jQuery 2.1.4 -->
    <script src="<?php echo $sujpath; ?>plugins/jQuery/jQuery-2.1.4.min.js"></script>
    <!-- Bootstrap 3.3.5 -->
    <script src="<?php echo $sujpath; ?>bootstrap/js/bootstrap.min.js"></script>
    <!-- DataTables -->
	<script src="<?php echo $sujpath; ?>plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="<?php echo $sujpath; ?>plugins/datatables/dataTables.bootstrap.min.js"></script>
    <!-- SlimScroll -->
    <script src="<?php echo $sujpath; ?>plugins/slimScroll/jquery.slimscroll.min.js"></script>
    <!-- FastClick -->
    <script src="<?php echo $sujpath; ?>plugins/fastclick/fastclick.min.js"></script>
    <!-- AdminLTE App -->
    <script src="<?php echo $sujpath; ?>dist/js/app.min.js"></script>
    <!-- AdminLTE for demo purposes -->
    <script src="<?php echo $sujpath; ?>dist/js/demo.js"></script>
    <!-- page script -->
   
    <script>
      $(document).ready(function() {
        $("#example1").DataTable();
      });
      
	function datat(){
	  alert("Data Deleted Successfully.");
      $(document).ready(function() {
        $("#example1").DataTable();
       
      });
    }
    function datat2(){
	  alert("Data Added Successfully");
      $(document).ready(function() {
        $("#example1").DataTable();
       
      });
    }
    function datat3(){
	  alert("Updated Successfully");
      $(document).ready(function() {
        $("#example1").DataTable();
       
      });
    }
   </script>  
   
   
   
  </body>
</html>
