<?php
session_start(); 
ob_start();
include("../../pidbco/pidbjoin.php");
$sujpath="./";

/* ---- Full Domain Register  ------ */
if(isset($_POST['full_dom_register']))
{
	$domtype   = $_POST['domtype'];
	$sort      = $_POST['domsort'];
	$today_dat = date('Y/m/d');
?>

<div style=" float: right;">
<a href="domain_reg_print.php?type=<?php echo base64_encode($domtype); ?>&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 width="11%">Reg Date</th>
<th width="15%">Expiry Date</th>
<th width="5%">Status</th>
</tr>
</thead>
<tbody>
<?php
   if($domtype != ''){
   	
	if($domtype == 'Active'){
		$dom1 = " `d_renewel`>'$today_dat'";
	} else if($domtype == 'Deactive'){
		$dom1 = " `d_renewel`<'$today_dat'"; 
	} else {
		$dom1 = " 1=1 ";
	} 	
	
	
	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'];
           $myDateTime = DateTime::createFromFormat('d/m/Y', $d_renewel);
			$d_renewel9 = $myDateTime->format('Y/m/d');
          // $d_renewel9 	 = date_format($d_renewel,"Y/m/d");
           $datetime1    = new DateTime($d_renewel9);
           $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 $rs['d_regdate']; ?></td>
   	<td><?php echo $rs['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>
 <script>
    $(document).ready(function() {
        $("#example1").DataTable();
    });
 </script>   
	
<?php  }
?>
