<?php 
include 'connection.php';

if (isset($_POST['showUsers'])) {
         $query = "SELECT * FROM new_invoice order by id desc limit 0,500";
         $result = mysqli_query($con,$query);

                ?>
                <div class="table-responsive">
              <table id="example2" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Websitename</th>
                  <th>Email</th>
                  <th>Phone</th>
                  <th>Sign On</th>
                  <th>Country</th>
                  <th>Amount</th>
                  <th>Order Id</th>
                  <th>IP</th>
                  <th>Action</th>
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                  <td class="sorting_1"><?php echo $row['websitename'];?></td>
                  <td><?php echo $row['pay_to_email']?></td>
                  <td><?php echo $row['c_number']?></td>
                  <td><?php echo date('M j Y ', strtotime($row['dates']));?></td>
                  <td><?php echo $row['country']?></td>
                  <td><?php echo $row['amount']?></td>
                   <td><?php echo $row['invoice_id']?></td>
                  <?php 
                  $user_Id =$row['id'];
                  $query2 = "SELECT * FROM `user_ip` where user_id ='$user_Id' ";
                  $result2 = mysqli_query($con,$query2);
                  $row2 = mysqli_fetch_assoc($result2);
                  ?>
                    <td><?php echo $row2['user_ip']?></td>
                  <td>
                      <a class="btn btn-info btn-sm profile"  data-value="<?php echo $row['id'];?>">Veiw</a>
                      <a class="btn btn-danger btn-sm" id="userId" data-value="<?php echo $row['id'];?>">Delete</a>
                  </td>
                </tr>
                <?php } ?>
                 </tbody>              
              </table>
              </div>
              <script type="text/javascript">
              	 $(function () {
   					
			    $('#example2').DataTable({
			      "paging": true,
			      "lengthChange": true,
			      "searching": true,
			      "ordering": true,
			      "order":[[3,"desc"]],
			      "info": true,
			      "autoWidth": true
			    });
			  });
              </script>

              <?php
	
}elseif ( isset($_POST['ipUser'])) {

	$query = "SELECT new_invoice.id,new_invoice.pay_to_email,new_invoice.shortname,new_invoice.amount,user_ip.user_ip
				FROM user_ip JOIN new_invoice ON new_invoice.`id` = user_ip.`user_id` order by id desc";
	$result = mysqli_query($con,$query);

	?>
		 <table id="example5" class="table table-bordered table-striped">
                <thead>
                <tr>
                 
                  <th>Email</th>
                  <th>Short Name</th>
                  <th>Amount</th>
                  <th>IP</th>
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                
                  <td><?php echo $row['pay_to_email']?></td>
                  <td><?php echo $row['shortname']?></td>
                  <td><?php echo $row['amount']?></td>
                  <td><?php echo $row['user_ip']?></td>
                </tr>
                <?php } ?>
               

              </tbody>              
              </table>
              <script type="text/javascript">
              	 $(function () {
   					
			    $('#example5').DataTable({
			      "paging": true,
			      "lengthChange": true,
			      "searching": true,
			      "ordering": true,
			      "info": true,
			      "autoWidth": true
			    });
			  });
              </script>

	<?php
	
}elseif (isset($_POST['decline'])) {
         $query = "SELECT new_invoice.`pay_to_email`,count(new_invoice.pay_to_email) as atempt,new_invoice.`dates`,new_invoice.`c_number`,new_invoice.`amount`,new_invoice.`invoice_id`,new_invoice.`country`,new_invoice.`websitename`,user_status.`status`,user_status.`reason_code` FROM user_status
                    JOIN new_invoice ON new_invoice.`id` = user_status.`user_id` WHERE user_status.`status` = 'Decline'
                    group by new_invoice.pay_to_email
                    order by user_status.id desc";
         $result = mysqli_query($con,$query);

                ?>
                <div class="table-responsive">
              <table id="example6" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Website</th>
                  <th>Email</th>
                  <th>Attempt</th>
                  <th>Phone</th>
                  <th>Date</th>
                  <th>Country</th>
                  <th>Amount</th>
                  <th>Reason Code</th>
                  <th>Invoice Id</th>
                  <th>Status</th>
                  <th>Action</th>
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                    <td class="sorting_1"><?php echo $row['websitename'];?></td>
                  <td class="sorting_1"><?php echo $row['pay_to_email'];?></td>
                  <td><?php echo $row['atempt']?></td>
                  <td><?php echo $row['c_number']?></td>
                  <td><?php echo date('M j Y ', strtotime($row['dates']));?></td>
                  <td><?php echo $row['country']?></td>
                   <td><?php echo $row['amount']?></td>
                   <td><?php echo $row['reason_code']?></td>
                 <td><?php echo $row['invoice_id']?></td>
                  <td><?php echo $row['status']?></td>
                  <td><a class="btn btn-danger" data-value="<?php echo $row['pay_to_email']?>" style="color:white" id="emailTo">Send Email</a></td>
                </tr>
                <?php } ?>
                 </tbody>              
              </table>
              </div>
              <script type="text/javascript">
              	$(document).ready(function() {
				    $('#example6').DataTable( {
				        paging: true,
					   pageLength: 10,
					    "ordering": true,
			           "order":[[3,"desc"]],
				    });
				});
              </script>

              <?php
	
}elseif (isset($_POST['date'])) {
        
      echo $type  = $_POST['type'];
       $date  = $_POST['date'];
       $array = explode("-", $date);

$date1 = $array[0];
$timestamp = strtotime($date1);
$newDate = date('Y-m-d', $timestamp); 

 $date2 = $array[1];
$timestamp2 = strtotime($date2);
$newDate2 = date('Y-m-d', $timestamp2); 


if($type != ''){
    $query = "SELECT new_invoice.*,user_status.status,user_status.created_at FROM user_status
    join new_invoice on new_invoice.id = user_status.user_id
    WHERE user_status.created_at >= '$newDate' AND user_status.created_at <= '$newDate2'
    AND user_status.status = '$type'";
    
}else{
    $query = "SELECT * FROM new_invoice WHERE dates >= '$newDate' AND dates <= '$newDate2'";
}



	
$result = mysqli_query($con,$query);

                ?>
              <table id="example7" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Websitename</th>
                  <th>Email</th>
                  <th>Phone</th>
                  <th>Dates</th>
                  <th>Country</th>
                  <th>Invoice Id</th>
                  <th>Amount</th>
                  
                 
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                    <td class="sorting_1"><?php echo $row['websitename'];?></td>
                  <td class="sorting_1"><?php echo $row['pay_to_email'];?></td>
                    <td class="sorting_1"><?php echo $row['c_number'];?></td>
                   <td><?php echo date('M j Y ', strtotime($row['dates']));?></td>
                   <td><?php echo $row['country']?></td>
                  <td><?php echo $row['invoice_id']?></td>
                  <td><?php echo $row['amount']?></td>
                 
                </tr>
                <?php } ?>
                 </tbody>              
              </table>
              
              <script type="text/javascript">
              	$(document).ready(function() {
				    $('#example7').DataTable( {
				        paging: true,
					   pageLength: 10,
					   "order":[[3,"desc"]],
				    });
				});
              </script>

              <?php
	

}elseif (isset($_GET['exportDate'])) {
    
   $type = $_GET['type'];
    $bank = $_GET['bank'];
	$date  = $_GET['exportDate'];
       $array = explode("-", $date);

$date1 = $array[0];
$timestamp = strtotime($date1);
$newDate = date('Y-m-d', $timestamp); 

 $date2 = $array[1];
$timestamp2 = strtotime($date2);
$newDate2 = date('Y-m-d', $timestamp2); 

 header("Content-type: application/vnd-ms-excel");  //for ms excel
	// Defines the name of the export file "export.xls"
	header("Content-Disposition: attachment; filename=".date('d').$type.".xls");
	header('Cache-Control: no-cache, no-store, must-revalidate');
	header('Pragma: no-cache');
	header('Expires: 0');
	

	  $query = "SELECT new_invoice.*,user_status.* FROM new_invoice 
	    join user_status on user_status.user_id = new_invoice.id
	    WHERE dates >= '$newDate' AND dates <= '$newDate2'
	    and user_status.status = '$type'
	    and user_status.bank = '$bank'"; 
	
$result = mysqli_query($con,$query);
?>
 <div class="mail-box">
  <aside class="lg-side">
    <div class="inbox-head">
      <h3>Report Member Led</h3>
    </div>
<table class="table table-striped table-bordered table-hover">
            <tr>
             <th>Email</th>
            <th>Country</th>
            <th>Transation Id</th>
            <th>Reason Code</th>
            <th>Date</th>
           
            
<?php
while($row = mysqli_fetch_assoc($result)){?>
<tr>
                 <td><?php echo $row['pay_to_email'] ?></td>
                 <td><?php echo $row['country'] ?></td>
                  <td><?php echo$row['transaction_id'] ?></td>
                  <td><?php echo $row['reason_code'] ?></td>
                   <td><?php echo $row['created_at'] ?></td>
                 
              
                    
 </tr>
<?php 
}  
?></table><?php
}elseif (isset($_POST['reporting'])) {

	?>
		<section class="content">
      <div class="card card-info">
              <div class="card-header">
                <h3 class="card-title">Custom Graph Veiw</h3>
              </div>
              <div class="card-body">
                <div class="row">
                  <div class="col-4">
                    
                 <select class="form-control" id="dateGraph">
                     <option value="">Select Period</option>
                     <option value="7">Last 7 Days</option>
                      <option value="30">Last  Month</option>
                      <option value="90">Last  3 Month</option>
                      <option value="365">Last 1 Year</option>
                 </select>
                  </div>
                  <div class="col-4">
                    <select class="form-control" id="websitename">
                        
                      <option value="">Select Domain</option>
                      <?php 
                       
                        $query = "SELECT DISTINCT(websitename),shortname FROM new_invoice";
                        $result = mysqli_query($con,$query);
                        while ($row = mysqli_fetch_assoc($result)) {
                          ?>
                          <option value="<?php echo $row['shortname'] ?>"><?php echo $row['websitename'] ?></option>

                          <?php
                        }

                      ?>
                    </select>
                  </div>
                  <div class="col-2">
                   <a class="btn btn-info" id="customGraph">Genrate</a>
                  </div>
                </div>
              </div>
              <!-- /.card-body -->
            </div>
      <div class="container-fluid">
        <div class="row">
          <div class="col-md-6">
            <!-- AREA CHART -->
            
            <!-- /.card -->

            <!-- DONUT CHART -->
            <div class="card card-danger">
              <div class="card-header">
                <h3 class="card-title">Top Leading Domain</h3>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                </div>
              </div>
              <div class="card-body">
                <canvas id="doughnut-chartcanvas-2" style="height: 286px; width: 572px;" width="572" height="286"></canvas>
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->

          </div>
          <!-- /.col (LEFT) -->
          <div class="col-md-6">
            <!-- LINE CHART -->
          
            <!-- /.card -->

            <!-- BAR CHART -->
            <div class="card card-success">
              <div class="card-header">
                <h3 class="card-title" id="monthTitle">Monthy leads</h3>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                </div>
              </div>
              <div class="card-body">
                <div class="chart">
                  <canvas id="barChart" style="height: 266px; width: 532px;" width="532" height="266"></canvas>
                </div>
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
             <div class="card card-success">
              <div class="card-header">
                <h3 class="card-title" id="monthTitle">Leads By Country</h3>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                </div>
              </div>
              <div class="card-body">
                <div class="chart">
                  <canvas id="cadoughnut-chartcanvas-2" style="height: 266px; width: 532px;" width="532" height="266"></canvas>
                </div>
              </div>
              <!-- /.card-body -->
            </div>
          </div>
          <!-- /.col (RIGHT) -->
        </div>
        <!-- /.row -->
      </div><!-- /.container-fluid -->
    </section>
<script src="plugins/chart.js/Chart.min.js"></script>
    <script>
       $(document).ready(function () {
            showGraph();
        });


        function showGraph()
        {
            {
                $.post("data.php",
                function (data)
                {
                   
                     var name = [];
                    var marks = [];

                    for (var i in data) {

                        if( data[i].NUM > 100){
                        name.push(data[i].shortname);
                        marks.push(data[i].NUM);
                    }

                        
                    }

                    var chartdata = {
                        labels: name,
                        datasets: [
                            {
                                label: 'Total Leads',
                                backgroundColor: ["#35ACF7","#FCDE52", "#35ACF7", "#7CF944", "#1B3808","#633E13", "#633E13","#E62277","#989928","#6F2DA8","#7CF944","#FE2416","#35ACF7","#FCDE52","#35ACF7","#63734F","#63734F","#35ACF7","#63734F","#C71E84","#35ACF7","#7CF944","#63734F","#63734F"],
                                borderColor: '#ffff',
                                hoverBackgroundColor: '#CCCCCC',
                                hoverBorderColor: '#666666',
                                data: marks
                            }
                        ]
                    };

                    var graphTarget = $("#doughnut-chartcanvas-2");

                    var barGraph = new Chart(graphTarget, {
                        type: 'doughnut',
                        data: chartdata
                    });
                });
            }
        }
         $(document).ready(function () {
            showGraph6();
        });


        function showGraph6()
        {
            {
                $.post("monthData.php",
                function (data)
                {
                   
                     var name = [];
                    var marks = [];
                console.log(data.month);
                    for (var i in data) {

                        
                        name.push(data[i].month);
                        marks.push(data[i].total);
                    

                        
                    }

                    var chartdata = {
                        labels: name,
                        datasets: [
                            {
                                label: 'Total Leads',
                                backgroundColor: ["#35ACF7","#018866", "#722F37", "#722F37", "#1B3808","#633E13", "#633E13","#E62277","#989928","#6F2DA8","#7CF944","#FE2416",],
                                borderColor: '#46d5f1',
                                hoverBackgroundColor: '#CCCCCC',
                                hoverBorderColor: '#666666',
                                data: marks
                            }
                        ]
                    };

                    var graphTarget = $("#barChart");

                    var barGraph = new Chart(graphTarget, {
                        type: 'bar',
                        data: chartdata
                    });
                });
            }
        }
       $(document).ready(function () {
            showGraph7();
        });


        function showGraph7()
        {
            {
                $.post("countryData.php",
                function (data)
                {
                   
                     var name = [];
                    var marks = [];

                    for (var i in data) {

                        if( data[i].NUM > 50){
                        name.push(data[i].country);
                        marks.push(data[i].NUM);
                    }

                        
                    }

                    var chartdata = {
                        labels: name,
                        datasets: [
                            {
                                label: 'Total Leads',
                                backgroundColor: ["#35ACF7","#FCDE52", "#35ACF7", "#7CF944", "#1B3808","#633E13", "#633E13","#E62277","#989928","#6F2DA8","#7CF944","#FE2416","#35ACF7","#FCDE52","#35ACF7","#63734F","#63734F","#35ACF7","#63734F","#C71E84","#35ACF7","#7CF944","#63734F","#63734F"],
                                borderColor: '#ffff',
                                hoverBackgroundColor: '#CCCCCC',
                                hoverBorderColor: '#666666',
                                data: marks
                            }
                        ]
                    };

                    var graphTarget = $("#cadoughnut-chartcanvas-2");

                    var barGraph = new Chart(graphTarget, {
                        type: 'pie',
                        data: chartdata
                    });
                });
            }
        }
$(function() {

    var start = moment().subtract(29, 'days');
    var end = moment();

    function cb(start, end) {
        $('#reportrangeGraph span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
    }

    $('#reportrangeGraph').daterangepicker({
        startDate: start,
        endDate: end,
        ranges: {
           'Today': [moment(), moment()],
           'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
           'Last 7 Days': [moment().subtract(6, 'days'), moment()],
           'Last 30 Days': [moment().subtract(29, 'days'), moment()],
           'This Month': [moment().startOf('month'), moment().endOf('month')],
           'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
        }
    }, cb);

    cb(start, end);

    

});

    </script>

	<?php


}elseif (isset($_POST['webname'])) {
  $webname   = $_POST['webname'];
  $dateGraph = $_POST['dateGraph'];


  if($dateGraph =="7" && $webname != ""){


  }


}elseif(isset($_POST['payToEmail'])){
    $emailTo = $_POST['payToEmail'];
?>

<div class="card card-outline card-info">
            <div class="card-header">
              <h3 class="card-title">
               Send Email To User:
                <small><?php echo $emailTo; ?></small>
              </h3>
              <!-- tools box -->
              
              <!-- /. tools -->
            </div>
            <!-- /.card-header -->

<div class="card-body">
<form method="POST" action="emailSend.php">
<label>USER EMAIL</label>
<input type="text" name="emailTo" class="form-control" value="<?php echo $emailTo?>"><br>
<textarea class="textarea" id="#editor1" name="emailText" style="width: 100%; height: 200px; font-size: 14px; line-height: 18px; border: 1px solid rgb(221, 221, 221); padding: 10px;" placeholder="Place some text here"></textarea>
<input type="Submit" class="btn btn-success pull-right" name="sendEmail" value="Send">

</form>
              </div>
              
           
          </div>

<?php


}elseif(isset($_POST['groups'])){

   $query = "SELECT * FROM domain_groups order by id Desc";
         $result = mysqli_query($con,$query);

                ?>
                <a href="javascript:void(0)" class="btn btn-info pull-right" id="addGroup"> Add Group</a><br /><br />
              <table id="example2" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Group Name</th>
                  <th>Group Type</th>
                  <th>Create At</th>
                  <th>Action</th>
                 
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                  <td class="sorting_1"><?php echo $row['group_name'];?></td>
                  <td><?php echo $row['group_type']?></td>
                  <td><?php echo $row['dates']?></td>
                  <td><a class="btn btn-info" id="viewGroup" data-value="<?php echo $row['id']?>" style="color:white">Veiw Group</a> ||  <a class="btn btn-success" id="editGroup" data-value="<?php echo $row['id']?>" style="color:white">Edit Group</a></td>
                </tr>
                <?php } ?>
                 </tbody>              
              </table>
              <script type="text/javascript">
                 $(function () {
            
          $('#example2').DataTable({
            "paging": true,
            "lengthChange": true,
            "searching": true,
            "ordering": true,
            "info": true,
            "autoWidth": true
          });
        });
              </script>

              <?php
}elseif(isset($_POST['addGroup'])){
?>
    <div class="card card-warning">
              <div class="card-header">
                <h3 class="card-title">Add New Group</h3>
              </div>
              <!-- /.card-header -->
              <div class="card-body">
                <form role="form">
                  <!-- text input -->
                  <div class="form-group">
                    <label>Enter Group Name</label>
                    <input type="text" class="form-control" id="groupName" placeholder="Enter ...">
                  </div>

                  <!-- input states -->
                  <div class="form-group has-success">
                    <label class="control-label" for="inputSuccess">Enter Type</label>
                    <input type="text" class="form-control" id="groupType" placeholder="Enter ...">
                  </div>
                
                  <!-- select -->
               
                  <!-- Select multiple-->
                  <div class="form-group">
                    <label>Insert Multiple Domain</label>
                   <div id="tags">
                  
                      <input type="text" class="form-control" value="" placeholder="Add a Domain" />
                    </div>
                  </div>
                  <input type="button" name="addGroup" class="btn btn-info pull-right" value="Add Group">
                </form>
              </div>
              <!-- /.card-body -->
            </div>
            <script type="text/javascript">
              $(function(){

              $('#tags input').on('focusout', function(){    
                var txt= this.value.replace(/[^a-zA-Z0-9\+\-\.\#]/g,''); // allowed characters list
                if(txt) $(this).before('<span class="tag" style="color:black">'+ txt +'</span> &nbsp;&nbsp; &nbsp;');
                this.value="";
                this.focus();
              }).on('keyup',function( e ){
                // comma|enter (add more keyCodes delimited with | pipe)
                if(/(188|13)/.test(e.which)) $(this).focusout();
              });
              
              $('#tags').on('click','.tag',function(){
                 if( confirm("Really delete this tag?") ) $(this).remove(); 
              });

            });
            </script>
<?php
}elseif(isset($_POST['groupName'])){

 $domains   = $_POST['values'];
 $groupName = $_POST['groupName'];
 $groupType = $_POST['groupType'];
 $date = date("Y-m-d");
 $query = "Insert into `domain_groups` values('','$groupName','$groupType','$date')";
 $result= mysqli_query($con,$query);

 echo $last_id = mysqli_insert_id($con);

 foreach ($domains as $key => $value) {
      
      $query = "Insert into `domains` values('','$value','$last_id','$date')";
       $result= mysqli_query($con,$query);
 }

 if ($result) {
        echo "inserted";
 }

}elseif(isset($_POST['groupId'])) {

  $groupId =  $_POST['groupId'];
  $query   = "SELECT * FROM domains where group_id  = '$groupId'";
  $result  = mysqli_query($con,$query);
?>
   <table id="example2" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Domain Name </th>
                  <th>Create At</th>
                 
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                 
                  <td><?php echo $row['domain_name']?></td>
                  <td><?php echo $row['create_at']?></td>
                 
                </tr>
                <?php } ?>
                 </tbody>              
              </table>
              <?php 
}elseif(isset($_POST['groupEditId'])){

  $groupId =  $_POST['groupEditId'];
  $query   = "SELECT * FROM domain_groups where id  = '$groupId'";
  $result  = mysqli_query($con,$query);
  $row = mysqli_fetch_assoc($result);
?>
    <div class="card card-warning">
              <div class="card-header">
                <h3 class="card-title">Edit Group</h3>
              </div>
              <!-- /.card-header -->
              <div class="card-body">
                <form role="form">
                  <!-- text input -->
                  <div class="form-group">
                    <label>Enter Group Name</label>
                    <input type="text" class="form-control" id="editgroupName" value="<?php echo $row['group_name']?>" placeholder="Enter ...">
                  </div>

                  <!-- input states -->
                  <div class="form-group has-success">
                    <label class="control-label" for="inputSuccess">Enter Type</label>
                    <input type="text" class="form-control" id="editgroupType" value="<?php echo $row['group_type']?>" placeholder="Enter ...">
                  </div>
                
                  <!-- select -->
               
                  <!-- Select multiple-->
                  <div class="form-group">
                    <label>Insert Multiple Domain</label>
                   <div id="tags">
                      <?php
                          $query   = "SELECT * FROM domains where group_id  = '$groupId'";
                          $result  = mysqli_query($con,$query);
                          while($row = mysqli_fetch_assoc($result)){
                            ?>
                              <span class="tag" style="color:black"><?php echo $row['domain_name']?></span> 
                            <?php

                          }

                      ?>
                      <input type="text" class="form-control" value="" placeholder="Add a Domain" />
                    </div>
                  </div>
                  <a id="editGroupold" data-value="<?php echo $groupId; ?>" class="btn btn-info pull-right" value="Add Group">Add Group</a>
                </form>
              </div>
              <!-- /.card-body -->
            </div>
            <script type="text/javascript">
              $(function(){

              $('#tags input').on('focusout', function(){    
                var txt= this.value.replace(/[^a-zA-Z0-9\+\-\.\#]/g,''); // allowed characters list
                if(txt) $(this).before('<span class="tag" style="color:black">'+ txt +'</span> &nbsp;&nbsp; &nbsp;');
                this.value="";
                this.focus();
              }).on('keyup',function( e ){
                // comma|enter (add more keyCodes delimited with | pipe)
                if(/(188|13)/.test(e.which)) $(this).focusout();
              });
              
              $('#tags').on('click','.tag',function(){
                 if( confirm("Really delete this tag?") ) $(this).remove(); 
              });

            });
            </script>
<?php
}elseif(isset($_POST['editgroupName'])){
 $id        = $_POST['id']; 
 $domains   = $_POST['values'];
 $groupName = $_POST['editgroupName'];
 $groupType = $_POST['editgroupType'];
 $date = date("Y-m-d");
 $query = "update `domain_groups` set grounp_name = '$groupName', group_type = '$groupType' where id = '$id'";

 $result= mysqli_query($con,$query);

 foreach ($domains as $key => $value) {
  $query = "select * from domains where domain_name = '$value' and group_id = '$id'";
  $result= mysqli_query($con,$query);
  $rows = mysqli_num_rows($result);

  if($rows == 0){ 
      $query = "Insert into `domains` values('','$value','$id','$date')";
       $result= mysqli_query($con,$query);
     }
 }

 if ($result) {
        echo "inserted";
 }

}elseif(isset($_POST['userId'])){
    $id = $_POST['userId'];
    $query = "delete from new_invoice where id = $id";
    $result = mysqli_query($con,$query);
    if($result){
        echo "success";
    }
}elseif (isset($_POST['sellReport'])) {

	?>
		<section class="content">
      <div class="card card-info">
              <div class="card-header">
                <h3 class="card-title">Sell Graph Veiw</h3>
              </div>
              <div class="card-body">
                <div class="row">
                  <div class="col-2">
                    <input type="text" class="form-control" placeholder="From" id="from" name="from">
                    </div>
                    <div class="col-2">
                    <input type="text" class="form-control" placeholder="To" id="to" name="to">
                    
                  </div>
                  <div class="col-4">
                    <select class="form-control" id="websitenameDec">
                      <option value="">Select Domain</option>
                      <?php 
                        $query = "SELECT DISTINCT(websitename),shortname FROM new_invoice";
                        $result = mysqli_query($con,$query);
                        while ($row = mysqli_fetch_assoc($result)) {
                          ?>
                          <option value="<?php echo $row['shortname'] ?>"><?php echo $row['websitename'] ?></option>

                          <?php
                        }

                      ?>
                    </select>
                  </div>
                  <div class="col-2">
                   <a class="btn btn-info" id="customGraphDec">Genrate</a>
                  </div>
                </div>
              </div>
              <!-- /.card-body -->
            </div>
      <div class="container-fluid">
        <div class="row">
          <div class="col-md-6">
            <!-- AREA CHART -->
            
            <!-- /.card -->

            <!-- DONUT CHART -->
            <div class="card card-danger">
              <div class="card-header">
                <h3 class="card-title">Top Decline Domain</h3>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                </div>
              </div>
              <div class="card-body">
                <canvas id="doughnut-chartcanvas-3" style="height: 286px; width: 572px;" width="572" height="286"></canvas>
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->

          </div>
          <!-- /.col (LEFT) -->
          <div class="col-md-6">
            <!-- LINE CHART -->
          
            <!-- /.card -->

            <!-- BAR CHART -->
            <div class="card card-success">
              <div class="card-header">
                <h3 class="card-title" id="monthTitle">Monthy Decline</h3>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                </div>
              </div>
              <div class="card-body">
                <div class="chart">
                  <canvas id="barChart" style="height: 266px; width: 532px;" width="532" height="266"></canvas>
                </div>
              </div>
              <!-- /.card-body -->
            </div>
            </div>
            </div>
            <!-- /.card -->
             <div class="row">
          <div class="col-md-6">
             <div class="card card-info">
              <div class="card-header">
                <h3 class="card-title" id="monthTitle">Decline By Country</h3>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                </div>
              </div>
              <div class="card-body">
                <div class="chart">
                  <canvas id="cadoughnut-chartcanvas-2" style="height: 266px; width: 532px;" width="532" height="266"></canvas>
                </div>
              </div>
              <!-- /.card-body -->
            </div>
          </div>
          
           <div class="col-md-6">
             <div class="card card-warning">
              <div class="card-header">
                <h3 class="card-title" id="monthTitle">Decline By Bank</h3>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                </div>
              </div>
              <div class="card-body">
                <div class="chart">
                  <canvas id="bank-Decline" style="height: 266px; width: 532px;" width="532" height="266"></canvas>
                </div>
              </div>
              <!-- /.card-body -->
            </div>
          </div>
          <!-- /.col (RIGHT) -->
        </div>
        <!-- /.row -->
      </div><!-- /.container-fluid -->
    </section>
<script src="plugins/chart.js/Chart.min.js"></script>

    <script>
       $(document).ready(function () {
            showGraph();
        });


        function showGraph()
        {
            {
                $.post("data.php?topDec=true",
                function (data)
                {
                   
                     var name = [];
                    var marks = [];

                    for (var i in data) {

                       
                        name.push(data[i].shortname);
                        marks.push(data[i].Total);
                    

                        
                    }

                    var chartdata = {
                        labels: name,
                        datasets: [
                            {
                                label: name,
                                backgroundColor: ["#35ACF7","#FCDE52", "#7CF944", "#1B3808","#633E13", "#633E13","#E62277","#989928","#6F2DA8","#7CF944","#FE2416","#35ACF7","#FCDE52","#35ACF7","#63734F","#63734F","#35ACF7","#63734F","#C71E84","#35ACF7","#7CF944","#63734F","#63734F"],
                                borderColor: '#ffff',
                                hoverBackgroundColor: '#CCCCCC',
                                hoverBorderColor: '#666666',
                                data: marks
                            }
                        ]
                    };

                    var graphTarget = $("#doughnut-chartcanvas-3");

                    var barGraph = new Chart(graphTarget, {
                        type: 'pie',
                        data: chartdata
                    });
                    
                     var canvas = document.getElementById('doughnut-chartcanvas-3');
            canvas.onclick = function(evt) {
           var activePoint = barGraph.getElementAtEvent(evt)[0];
           var data = activePoint._chart.data;
          var datasetIndex = activePoint._datasetIndex;
          var label = data.datasets[datasetIndex].label[activePoint._index];
          var value = data.datasets[datasetIndex].data[activePoint._index];
          var nameDomain = label;
          $.post("response.php",{nameDomain:nameDomain},function(data){
              $("#userDATA").css("display","none");
              $("#homeDAta").html(data);
          })
};
                });
            }
           

           
        }
        
 
        
        
        
        
        
         $(document).ready(function () {
            showGraph6();
        });


        function showGraph6()
        {
            {
                $.post("monthData.php?decline=true",
                function (data)
                {
                   
                     var name = [];
                    var marks = [];

                    for (var i in data) {

                        name.push(data[i].month);
                        marks.push(data[i].total);
                    
                    }

                    var chartdata = {
                        labels: name,
                        datasets: [
                            {
                                label: 'Total Leads',
                                backgroundColor: ["#35ACF7","#018866", "#722F37", "#722F37", "#1B3808","#633E13", "#633E13","#E62277","#989928","#6F2DA8","#7CF944","#FE2416",],
                                borderColor: '#46d5f1',
                                hoverBackgroundColor: '#CCCCCC',
                                hoverBorderColor: '#666666',
                                data: marks
                            }
                        ]
                    };

                    var graphTarget = $("#barChart");

                    var barGraph = new Chart(graphTarget, {
                        type: 'bar',
                        data: chartdata
                    });
                });
            }
        }
       $(document).ready(function () {
            showGraph7();
        });


        function showGraph7()
        {
            {
                $.post("countryData.php?country=true",
                function (data)
                {
                   
                     var name = [];
                    var marks = [];

                    for (var i in data) {
                        name.push(data[i].country);
                        marks.push(data[i].NUM);

                        
                    }

                    var chartdata = {
                        labels: name,
                        datasets: [
                            {
                                label: 'Total Leads',
                                backgroundColor: ["#35ACF7","#FCDE52","#7CF944"],
                                borderColor: '#ffff',
                                hoverBackgroundColor: ["#35ACF7","#FCDE52","#7CF944"],
                                hoverBorderColor: '#666666',
                                data: marks
                            }
                        ]
                    };

                    var graphTarget = $("#cadoughnut-chartcanvas-2");

                    var barGraph = new Chart(graphTarget, {
                        type: 'pie',
                        data: chartdata,
                    });
                });
            }
        }
        
     $(document).ready(function () {
            showGraph8();
        });


        function showGraph8()
        {
            {
                $.post("countryData.php?bankDec=true",
                function (data)
                {
                   
                     var name = [];
                    var marks = [];

                    for (var i in data) {
                        name.push(data[i].bank);
                        marks.push(data[i].NUM);

                        
                    }

                    var chartdata = {
                        labels: name,
                        datasets: [
                            {
                                label: 'Total Leads',
                                backgroundColor: ["Red","#028269"],
                                borderColor: '#ffff',
                                hoverBackgroundColor: ["Red","#028269"],
                                hoverBorderColor: 'pink',
                                data: marks
                            }
                        ]
                    };

                    var graphTarget = $("#bank-Decline");

                    var barGraph = new Chart(graphTarget, {
                        type: 'pie',
                        data: chartdata,
                    });
                });
            }
        }
        
$(function() {

    var start = moment().subtract(29, 'days');
    var end = moment();

    function cb(start, end) {
        $('#reportrangeGraph span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
    }

    $('#reportrangeGraph').daterangepicker({
        startDate: start,
        endDate: end,
        ranges: {
           'Today': [moment(), moment()],
           'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
           'Last 7 Days': [moment().subtract(6, 'days'), moment()],
           'Last 30 Days': [moment().subtract(29, 'days'), moment()],
           'This Month': [moment().startOf('month'), moment().endOf('month')],
           'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
        }
    }, cb);

    cb(start, end);

    

});
$( function() {
		var dateFormat = "mm/dd/yy",
			from = $( "#from" )
				.datepicker({
					defaultDate: "+1w",
					changeMonth: true,
					numberOfMonths: 3
				})
				.on( "change", function() {
					to.datepicker( "option", "minDate", getDate( this ) );
				}),
			to = $( "#to" ).datepicker({
				defaultDate: "+1w",
				changeMonth: true,
				numberOfMonths: 3
			})
			.on( "change", function() {
				from.datepicker( "option", "maxDate", getDate( this ) );
			});

		function getDate( element ) {
			var date;
			try {
				date = $.datepicker.parseDate( dateFormat, element.value );
			} catch( error ) {
				date = null;
			}

			return date;
		}
	} );
    </script>

	<?php


}elseif (isset($_POST['paid'])) {
         $query = "SELECT new_invoice.*,`user_status`.`status`,user_status.created_at,user_status.bank FROM user_status 
                    JOIN new_invoice on new_invoice.id = user_status.user_id
                    WHERE user_status.status = 'Success'
                    order by new_invoice.dates Desc";
         $result = mysqli_query($con,$query);

                ?>
            <div class="table-responsive">
              <table id="example6" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Domain</th>
                  <th>Email</th>
                  <th>Phone</th>
                  <th>Date</th>
                  <th>Country</th>
                  <th>Invoice Id</th>
                  <th>Amount</th>
                  <th>Bank</th>
                 
                  
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                  <td><?php echo str_replace("www.","",$row['websitename'])?></td>
                  <td class="sorting_1"><?php echo $row['pay_to_email'];?></td>
                  <td class="sorting_1"><?php echo $row['c_number'];?></td>
                  <td><?php echo date('M j Y ', strtotime($row['created_at']));?></td>
                  <td><?php echo $row['country']?></td>
                  <td><?php echo $row['invoice_id']?></td>
                  <td><?php echo $row['amount']?></td>
                  <td><?php echo $row['bank']?></td>
                
                  </tr>
                <?php } ?>
                 </tbody>              
              </table>
            </div>
              <script type="text/javascript">
              	$(document).ready(function() {
				    $('#example6').DataTable( {
				        paging: true,
					   pageLength: 10,
					   "ordering": true,
			      "order":[[3,"desc"]],
				    });
				});
              </script>

              <?php
	
}elseif (isset($_POST['searchAr'])) {

	?>
		<section class="content">
      <div class="card card-info">
              <div class="card-header">
                <h3 class="card-title">Custom Graph Veiw</h3>
              </div>
              <div class="card-body">
                <div class="row">
                  <div class="col-2">
                    <input type="text" class="form-control" placeholder="From" id="from" name="from">
                    </div>
                    <div class="col-2">
                    <input type="text" class="form-control" placeholder="To" id="to" name="to">
                    
                  </div>
                  <div class="col-4">
                    <select class="form-control" id="websitenameDec">
                      <option value="">Success</option>
                      <option value="">Decline</option>
                      <option value="">Success Compression By Bank</option>
                      <option value="">Decline Compression By Bank</option>
                     
                    </select>
                     </div>
                  <div class="col-4">
                    <select class="form-control" id="websitenameDec">
                      <option value="">Select Domain</option>
                      <?php 
                        $query = "SELECT DISTINCT(websitename),shortname FROM new_invoice";
                        $result = mysqli_query($con,$query);
                        while ($row = mysqli_fetch_assoc($result)) {
                            if($row['websitename'] == ""){}else{
                          ?>
                          <option value="<?php echo $row['shortname'] ?>"><?php echo $row['websitename'] ?></option>

                          <?php
                            }
                        }

                      ?>
                    </select>
                     </div>
                  

                </div>
                <br />
                 <a class="btn btn-info float-right" id="customGraphDec">Genrate</a>

              </div>
              </div>
              <div class="row">
               <div class="col-md-12">
            <!-- LINE CHART -->
          
            <!-- /.card -->

            <!-- BAR CHART -->
            <div class="card card-success">
              <div class="card-header">
                <h3 class="card-title" id="monthTitle">Monthy Decline</h3>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                </div>
              </div>
              <div class="card-body">
                <div class="chart">
                  <canvas id="barChart" style="height: 266px; width: 532px;" width="532" height="266"></canvas>
                </div>
              </div>
              <!-- /.card-body -->
            </div>
            </div>
             </div>
        <script>
       $(document).ready(function () {
         $.post("countryData.php?Search=true",function (data){
                 
                   var Decline = [];
                    var Success = [];
                    var Days = [];
                    for (var i in data) {
                        Decline.push(data[i].Decline);
                        Success.push(data[i].Success);
                        Days.push(data[i].Day);
                
                        console.log(name);
                        
                    }  
  //get the line chart canvas
  var ctx = $("#barChart");

  //line chart data
  var data = {
    labels: Days,
    datasets: [
      {
        label: "Success",
        data: Success,
        backgroundColor: "Green",
        borderColor: "Green",
        fill: false,
        lineTension: 0,
        radius: 5
      },
      {
        label: "Decline",
        data: Decline,
        backgroundColor: "Red",
        borderColor: "Red",
        fill: false,
        lineTension: 0,
        radius: 5
      }
    ]
  };

  //options
  var options = {
    responsive: true,
    title: {
      display: true,
      position: "top",
      text: "Line",
      fontSize: 18,
      fontColor: "#111"
    },
    legend: {
      display: true,
      position: "top",
      labels: {
        fontColor: "#333",
        fontSize: 16
      }
    }
  };

  //create Chart class object
  var chart = new Chart(ctx, {
    type: "line",
    data: data,
    options: options
  });
  
                })
       })

 
    $( function() {
		var dateFormat = "mm/dd/yy",
			from = $( "#from" )
				.datepicker({
					defaultDate: "+1w",
					changeMonth: true,
					numberOfMonths: 3
				})
				.on( "change", function() {
					to.datepicker( "option", "minDate", getDate( this ) );
				}),
			to = $( "#to" ).datepicker({
				defaultDate: "+1w",
				changeMonth: true,
				numberOfMonths: 3
			})
			.on( "change", function() {
				from.datepicker( "option", "maxDate", getDate( this ) );
			});

		function getDate( element ) {
			var date;
			try {
				date = $.datepicker.parseDate( dateFormat, element.value );
			} catch( error ) {
				date = null;
			}

			return date;
		}
	} );
	</script>
              
                    
<?php
}elseif($_POST['nameDomain']){
    $name =  $_POST['nameDomain'];
    
    $query = "select * from new_invoice where shortname = '$name'";
    $result = mysqli_query($con,$query);
    $row2 = mysqli_fetch_assoc($result);
    $webname = str_replace("www.","",$row2['websitename']);
    ?>
    		<section class="content">
      <div class="card card-info">
              <div class="card-header">
                <h3 class="card-title">Sell Graph Veiw</h3>
              </div>
              <div class="card-body">
                <div class="row">
                  <div class="col-4">
                    <input type="text" class="form-control" placeholder="From" id="from" name="from">
                    </div>
                    <div class="col-4">
                    <input type="text" class="form-control" placeholder="To" id="to" name="to"> 
                  </div>
                  <div class="col-2">
                   <a class="btn btn-info" id="customGraphDec">Genrate</a>
                  </div>
                </div>
              </div>
              <!-- /.card-body -->
            </div>
      <div class="container-fluid">
        <div class="row">
          <div class="col-md-6">
            <!-- AREA CHART -->
            
            <!-- /.card -->

            <!-- DONUT CHART -->
            <div class="card card-danger">
              <div class="card-header">
                <h3 class="card-title"><?php echo 
                $webname?> Decline By Country  <span id="demo4" style="font-size: 18px"></span></h3>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                </div>
              </div>
              <div class="card-body">
                <canvas id="doughnut-chartcanvas-3" style="height: 286px; width: 572px;" width="572" height="286"></canvas>
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->

          </div>
          <!-- /.col (LEFT) -->
          <div class="col-md-6">
            <!-- LINE CHART -->
          
            <!-- /.card -->

            <!-- BAR CHART -->
            <div class="card card-success">
              <div class="card-header">
                <h3 class="card-title" id="monthTitle"><?php echo 
                $webname?> Succes By Country <span id="demo5" style="font-size: 18px"></span></h3>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                </div>
              </div>
              <div class="card-body">
                <div class="chart">
                  <canvas id="barChart" style="height: 266px; width: 532px;" width="532" height="266"></canvas>
                </div>
              </div>
              <!-- /.card-body -->
            </div>
            </div>
            </div>
            <!-- /.card -->
             <div class="row">
          <div class="col-md-6">
             <div class="card card-info">
              <div class="card-header">
                <h3 class="card-title" id="monthTitle"><?php echo 
                $webname?> Decline By Bank <span id="demo6" style="font-size: 18px"></span></h3>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                </div>
              </div>
              <div class="card-body">
                <div class="chart">
                  <canvas id="cadoughnut-chartcanvas-2" style="height: 266px; width: 532px;" width="532" height="266"></canvas>
                </div>
              </div>
              <!-- /.card-body -->
            </div>
          </div>
          
           <div class="col-md-6">
             <div class="card card-warning">
              <div class="card-header">
                <h3 class="card-title" id="monthTitle"><?php echo 
                $webname?> Succees By Bank <span id="demo7" style="font-size: 18px"></span></h3>

                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                </div>
              </div>
              <div class="card-body">
                <div class="chart">
                  <canvas id="bank-Decline" style="height: 266px; width: 532px;" width="532" height="266"></canvas>
                </div>
              </div>
              <!-- /.card-body -->
            </div>
          </div>
          <!-- /.col (RIGHT) -->
        </div>
        <!-- /.row -->
      </div><!-- /.container-fluid -->
    </section>
<script src="plugins/chart.js/Chart.min.js"></script>

    <script>
       $(document).ready(function () {
            showGraph();
        });


        function showGraph()
        {
            {
                $.post("data.php?domainName=<?php echo $name?>",
                function (data)
                {
                   
                     var name = [];
                    var marks = [];

                    for (var i in data) {

                       
                        name.push(data[i].country);
                        marks.push(data[i].NUM);
                    
                    }
                   var sum = 0;
                      for(var i=0; i < marks.length; i++){
                          sum += parseInt(marks[i]);
                          
                      }
                      $("#demo4").html("(Total "+sum+" )");
                    var chartdata = {
                        labels: name,
                        datasets: [
                            {
                                label: name,
                                backgroundColor: ["#35ACF7","#FCDE52", "#7CF944", "#1B3808","#633E13", "#633E13","#E62277","#989928","#6F2DA8","#7CF944","#FE2416","#35ACF7","#FCDE52","#35ACF7","#63734F","#63734F","#35ACF7","#63734F","#C71E84","#35ACF7","#7CF944","#63734F","#63734F"],
                                borderColor: '#ffff',
                                hoverBackgroundColor: '#CCCCCC',
                                hoverBorderColor: '#666666',
                                data: marks
                            }
                        ]
                    };

                    var graphTarget = $("#doughnut-chartcanvas-3");

                    var barGraph = new Chart(graphTarget, {
                        type: 'pie',
                        data: chartdata
                    });
                    
                     var canvas = document.getElementById('doughnut-chartcanvas-3');
            canvas.onclick = function(evt) {
           var activePoint = barGraph.getElementAtEvent(evt)[0];
           var data = activePoint._chart.data;
          var datasetIndex = activePoint._datasetIndex;
          var label = data.datasets[datasetIndex].label[activePoint._index];
          var value = data.datasets[datasetIndex].data[activePoint._index];
          var nameDomain = label;
          $.post("response.php",{nameDomain:nameDomain},function(data){
              alert(data);
          })
};
                });
            }
           

           
        }
        
 
        
        
        
        
        
         $(document).ready(function () {
            showGraph6();
        });


        function showGraph6()
        {
            {
                $.post("data.php?domainNameSuccess=<?php echo $name?>",
                function (data)
                {
                   
                     var name = [];
                    var marks = [];

                    for (var i in data) {

                        name.push(data[i].country);
                        marks.push(data[i].NUM);
                    
                    }
                     var sum = 0;
                      for(var i=0; i < marks.length; i++){
                          sum += parseInt(marks[i]);
                          
                      }
                      $("#demo5").html("(Total "+sum+" )");
                    var chartdata = {
                        labels: name,
                        datasets: [
                            {
                                label: 'Total Leads',
                                backgroundColor: ["#35ACF7","#FCDE52", "#7CF944", "#1B3808","#633E13", "#633E13","#E62277","#989928","#6F2DA8","#7CF944","#FE2416","#35ACF7","#FCDE52","#35ACF7","#63734F","#63734F","#35ACF7","#63734F","#C71E84","#35ACF7","#7CF944","#63734F","#63734F","#35ACF7","#FCDE52", "#7CF944", "#1B3808","#633E13", "#633E13","#E62277","#989928","#6F2DA8","#7CF944","#FE2416","#35ACF7","#FCDE52","#35ACF7","#63734F","#63734F","#35ACF7","#63734F","#C71E84","#35ACF7","#7CF944","#63734F","#63734F"],
                                borderColor: '#46d5f1',
                                hoverBackgroundColor: '#CCCCCC',
                                hoverBorderColor: '#666666',
                                data: marks
                            }
                        ]
                    };

                    var graphTarget = $("#barChart");

                    var barGraph = new Chart(graphTarget, {
                        type: 'bar',
                        data: chartdata
                    });
                });
            }
        }
       $(document).ready(function () {
            showGraph7();
        });


        function showGraph7()
        {
            {
                $.post("data.php?namebyBank=<?php echo $name?>",
                function (data)
                {
                   
                     var name = [];
                    var marks = [];

                    for (var i in data) {
                        name.push(data[i].bank);
                        marks.push(data[i].NUM);

                        
                    }
                     var sum = 0;
                      for(var i=0; i < marks.length; i++){
                          sum += parseInt(marks[i]);
                          
                      }
                      $("#demo6").html("(Total "+sum+" )");
                    var chartdata = {
                        labels: name,
                        datasets: [
                            {
                                label: 'Total Leads',
                                backgroundColor: ["#35ACF7","#FCDE52","#7CF944"],
                                borderColor: '#ffff',
                                hoverBackgroundColor: ["#35ACF7","#FCDE52","#7CF944"],
                                hoverBorderColor: '#666666',
                                data: marks
                            }
                        ]
                    };

                    var graphTarget = $("#cadoughnut-chartcanvas-2");

                    var barGraph = new Chart(graphTarget, {
                        type: 'doughnut',
                        data: chartdata,
                    });
                });
            }
        }
        
     $(document).ready(function () {
            showGraph8();
        });


        function showGraph8()
        {
            {
                $.post("data.php?namebyBankSuc=<?php echo $name?>",
                function (data)
                {
                   
                     var name = [];
                    var marks = [];

                    for (var i in data) {
                        name.push(data[i].bank);
                        marks.push(data[i].NUM);

                        
                    }
                    var sum = 0;
                      for(var i=0; i < marks.length; i++){
                          sum += parseInt(marks[i]);
                          
                      }
                      $("#demo7").html("(Total "+sum+" )");
                    var chartdata = {
                        labels: name,
                        datasets: [
                            {
                                label: 'Total Leads',
                                backgroundColor: ["Red","#028269"],
                                borderColor: '#ffff',
                                hoverBackgroundColor: ["Red","#028269"],
                                hoverBorderColor: 'pink',
                                data: marks
                            }
                        ]
                    };

                    var graphTarget = $("#bank-Decline");

                    var barGraph = new Chart(graphTarget, {
                        type: 'pie',
                        data: chartdata,
                    });
                });
            }
        }
        
$(function() {

    var start = moment().subtract(29, 'days');
    var end = moment();

    function cb(start, end) {
        $('#reportrangeGraph span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
    }

    $('#reportrangeGraph').daterangepicker({
        startDate: start,
        endDate: end,
        ranges: {
           'Today': [moment(), moment()],
           'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
           'Last 7 Days': [moment().subtract(6, 'days'), moment()],
           'Last 30 Days': [moment().subtract(29, 'days'), moment()],
           'This Month': [moment().startOf('month'), moment().endOf('month')],
           'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
        }
    }, cb);

    cb(start, end);

    

});
$( function() {
		var dateFormat = "mm/dd/yy",
			from = $( "#from" )
				.datepicker({
					defaultDate: "+1w",
					changeMonth: true,
					numberOfMonths: 3
				})
				.on( "change", function() {
					to.datepicker( "option", "minDate", getDate( this ) );
				}),
			to = $( "#to" ).datepicker({
				defaultDate: "+1w",
				changeMonth: true,
				numberOfMonths: 3
			})
			.on( "change", function() {
				from.datepicker( "option", "maxDate", getDate( this ) );
			});

		function getDate( element ) {
			var date;
			try {
				date = $.datepicker.parseDate( dateFormat, element.value );
			} catch( error ) {
				date = null;
			}

			return date;
		}
	} );
    </script>
    
    <?php
}elseif (isset($_POST['cancel'])) {
         $query = "SELECT new_invoice.`pay_to_email`,new_invoice.`dates`,new_invoice.`c_number`,new_invoice.`amount`,new_invoice.`websitename`,new_invoice.`invoice_id`,new_invoice.`country`,user_status.`status` FROM user_status
                    JOIN new_invoice ON new_invoice.`id` = user_status.`user_id` WHERE user_status.`status` = 'Cancel'";
         $result = mysqli_query($con,$query);

                ?>
            <div class="table-responsive">
              <table id="example6" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Websitename</th>
                  <th>Email</th>
                   <th>Phone</th>
                  <th>Date</th>
                  <th>Country</th>
                  <th>Invoice Id</th>
                  <th>Amount</th>
                  <th>Action</th>
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                  <td class="sorting_1"><?php echo $row['websitename'];?></td>
                  <td class="sorting_1"><?php echo $row['pay_to_email'];?></td>
                  <td class="sorting_1"><?php echo $row['c_number'];?></td>
                  <td><?php echo date('M j Y ', strtotime($row['dates']));?></td>
                  <td><?php echo $row['country']?></td>
                  <td><?php echo $row['invoice_id']?></td>
                  <td><?php echo $row['amount']?></td>
                  <td><a class="btn btn-danger" data-value="<?php echo $row['pay_to_email']?>" style="color:white" id="emailTo">Send Email</a></td>
                </tr>
                <?php } ?>
                 </tbody>              
              </table>
            </div>
              <script type="text/javascript">
              	$(document).ready(function() {
				    $('#example6').DataTable( {
				        paging: true,
					   pageLength: 10,
					    "ordering": true,
			           "order":[[2,"desc"]],
				    });
				});
              </script>

              <?php
	
}elseif (isset($_POST['pending'])) {
         $query = "SELECT new_invoice.`id`,new_invoice.`pay_to_email`,new_invoice.`dates`,new_invoice.`c_number`,new_invoice.`amount`,new_invoice.`websitename`,new_invoice.`invoice_id`,new_invoice.`country`,user_status.`status`,user_status.`created_at` FROM user_status
                    JOIN new_invoice ON new_invoice.`id` = user_status.`user_id` WHERE user_status.`status` = 'Padding'";
         $result = mysqli_query($con,$query);
         $i = 1;
                ?>
            <div class="table-responsive">
              <table id="example6" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th><input type="checkbox" id="selectAll" />All</th>
                  <th>Website</th>
                  <th>Email</th>
                  <th>Phone</th>
                  <th>Date</th>
                  <th>Country</th>
                  <th>Invoice Id</th>
                  <th>Amount</th>
                  <th>Action</th>
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                  <td><input type="checkbox" value="<?php echo $row['id']?>" id="<?php echo $i?>"/></td>
                  <td class="sorting_1"><?php echo $row['websitename'];?></td>
                  <td class="sorting_1"><?php echo $row['pay_to_email'];?></td>
                  <td class="sorting_1"><?php echo $row['c_number'];?></td>
                  <td><?php echo date('M j Y ', strtotime($row['created_at']));?></td>
                  <td><?php echo $row['country']?></td>
                  <td><?php echo $row['invoice_id']?></td>
                  <td><?php echo $row['amount']?></td>
                  <td><a class="btn btn-danger" data-value="<?php echo $row['pay_to_email']?>" style="color:white" id="emailTo">Send Email</a></td>
                </tr>
                <?php
                $i++;
                } ?>
                 </tbody>              
              </table>
            </div>
              <input type="button" class="btn btn-info" value = "Send Template" id="send">
              <script type="text/javascript">
              	$(document).ready(function() {
				    $('#example6').DataTable( {
				        paging: true,
					   pageLength: 10,
					    "ordering": true,
			           "order":[[3,"desc"]],
				    });
				    
			      $('#selectAll').click(function(e){
                    	var table= $(e.target).closest('table');
                    	$('td input:checkbox',table).attr('checked',e.target.checked);
                    });
                  $('#send').click(function(){
                        let a = [];
                $("td input:checkbox:checked").each(function() {
                    a.push($(this).val());
                });
             
                $.post("response.php",{Selected:a},function(data){
                    
                     $("#mainCard").html(data);
                })
                    	
                  })
                    
				});
              </script>

              <?php
	
}elseif (isset($_POST['montheReportSell'])) {
    ?>
          <div class="container-fluid">
        <!-- Small boxes (Stat box) -->
        <div class="row">
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-info">
              <div class="inner">
                 <?php 
             //    $con = mysqli_connect("localhost", "root", "", "jibran84_ach");
                 $today = date("Y-m-d");
                 $query = "SELECT count(*) as today FROM user_status where created_at = '$today' and status ='Success'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                ?>
                <h3><?php echo $row['today'];?></h3>
                <p>Today Paided User</p>
              </div>
              <div class="icon">
                <i class="ion ion-bag"></i>
              </div>
             
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-success">
              <div class="inner">
                <?php 
                 
                 $today = date("Y-m-d");
                 $query = "SELECT count(*) as week FROM user_status
                          WHERE created_at >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY
                          AND   created_at < curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY
                          and status = 'Success'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 
                ?>

                <h3><?php echo $row['week'];?></h3>

                <p>Last Week Paided Users</p>
              </div>
              <div class="icon">
                <i class="ion ion-stats-bars"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-warning">
              <div class="inner">
                 <?php 
                 
                 $today = date("Y-m-d");
                 $query = "SELECT count(*) as lastMonth FROM user_status
                        WHERE YEAR(created_at) = YEAR(CURRENT_DATE - INTERVAL 1 MONTH)
                        AND MONTH(created_at) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH)
                        and status = 'Success'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 
                ?>
                <h3><?php echo $row['lastMonth'];?></h3>

                <p>Last Month Paided Users</p>
              </div>
              <div class="icon">
                <i class="ion ion-person-add"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-danger">
              <div class="inner">
                <?php 
                 
                 $query = "SELECT  COUNT(*) total FROM user_status
                         WHERE YEAR(`created_at`) = YEAR(DATE_SUB(CURDATE(), INTERVAL 1 YEAR)) AND status='Success'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                ?>
                <h3><?php echo $row['total'];?></h3>

                <p>Last Year Paided Users</p>
              </div>
              <div class="icon">
                <i class="ion ion-pie-graph"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
        </div>
        <div class="row">
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box" style="background-color:#7CF944">
              <div class="inner">
                 <?php 
             //    $con = mysqli_connect("localhost", "root", "", "jibran84_ach");
                 $today = date("Y-m-d");
                 $query = "SELECT sum(new_invoice.amount) as total from user_status 
                            join new_invoice on new_invoice.id = user_status.user_id
                            WHERE user_status.status = 'Success'
                            AND user_status.created_at = '$today'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 $sell = $row['total'];
                 if($sell == ""){
                     $sell = "0";
                 }
                ?>
                <h3><?php echo "$" .$sell;?></h3>
                <p>Today Sell</p>
              </div>
              <div class="icon">
               <i class="fa fa-shopping-cart"></i>
              </div>
             
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-info" >
              <div class="inner">
                <?php 
                 
                 $today = date("Y-m-d");
                 $query = "SELECT sum(new_invoice.amount) as total from user_status 
                           join new_invoice on new_invoice.id = user_status.user_id
                           WHERE user_status.created_at >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY
                           AND   user_status.created_at < curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY
                           and user_status.status = 'Success'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 
                ?>

                <h3><?php echo "$". $row['total'];?></h3>

                <p>Last Week Sell</p>
              </div>
              <div class="icon">
                <i class="fa fa-money"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box" style="background-color:#E62277">
              <div class="inner">
                 <?php 
                 
                 $today = date("Y-m-d");
                 $query = "SELECT sum(new_invoice.amount) as total from user_status 
       join new_invoice on new_invoice.id = user_status.user_id
        WHERE YEAR(user_status.created_at) = YEAR(CURRENT_DATE - INTERVAL 1 MONTH)
      AND MONTH(user_status.created_at) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH)
       and user_status.status = 'Success'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 $total = $row['total'];
                
                  if(is_null($total)){
                     $total = "0";
                 }
                 
                 
                ?>
                <h3><?php echo "$".$total?></h3>

                <p>Last Month Sell</p>
              </div>
              <div class="icon">
                <i class="fa  fa-check"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box" style="background-color:#35ACF7">
              <div class="inner">
                <?php 
                 
                 $query = "SELECT sum(new_invoice.amount) as total from user_status 
                           join new_invoice on new_invoice.id = user_status.user_id
                           WHERE YEAR(user_status.`created_at`) = YEAR(DATE_SUB(CURDATE(), INTERVAL 1 YEAR))
                           and user_status.status = 'Success'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 $total = $row['total'];
                  if(is_null($total)){
                     $total = "0";
                 }
                ?>
                <h3><?php echo "$".$total;?></h3>

                <p>Last Year Sell</p>
              </div>
              <div class="icon">
                <i class="ion ion-person-add"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
        </div>
         <div class="row">
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-info">
              <div class="inner">
                 <?php 
             //    $con = mysqli_connect("localhost", "root", "", "jibran84_ach");
                 $today = date("Y-m-d");
                 $query = "SELECT sum(new_invoice.amount) as total
                            FROM   user_status
                            join new_invoice on new_invoice.id = user_status.user_id
                            WHERE  YEARWEEK(user_status.`created_at`, 1) = YEARWEEK(CURDATE(), 1)                        
                            and user_status.status = 'Success'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 $num_row = mysqli_num_rows($result);
                 $total = $row['total'];
                  if(is_null($total)){
                     $total = "0";
                 }
                ?>
                <h3><?php echo "$".$total;?></h3>
                <p>Current Week Sell</p>
              </div>
              <div class="icon">
                <i class="ion ion-bag"></i>
              </div>
             
            </div>
          </div>
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-warning">
              <div class="inner">
                 <?php 
             //    $con = mysqli_connect("localhost", "root", "", "jibran84_ach");
                 $today = date("Y-m-d");
                 $query = "SELECT sum(new_invoice.amount) as total
                            FROM  user_status
                            join new_invoice on new_invoice.id = user_status.user_id
                            WHERE MONTH(user_status.`created_at`) = MONTH(CURRENT_DATE())
                            AND YEAR(user_status.`created_at`) = YEAR(CURRENT_DATE())
                            and user_status.status = 'Success'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 $num_row = mysqli_num_rows($result);
                  
                 $total = $row['total'];
                  if(is_null($total)){
                     $total = "0";
                 }
                
                ?>
                <h3><?php echo "$".$total;?></h3>
                <p>Current Month Sell</p>
              </div>
              <div class="icon">
                <i class="ion ion-bag"></i>
              </div>
             
            </div>
          </div>
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-danger">
              <div class="inner">
                 <?php 
             //    $con = mysqli_connect("localhost", "root", "", "jibran84_ach");
                 $today = date("Y-m-d");
                 $query = "SELECT SUM(new_invoice.amount) as total FROM user_status
                             JOIN new_invoice on new_invoice.id = user_status.user_id
                             WHERE YEAR(user_status.created_at) = YEAR(CURDATE())
                             AND user_status.status = 'Success'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                ?>
                <h3><?php echo "$".$row['total'];?></h3>
                <p>Current Year Sell</p>
              </div>
              <div class="icon">
                <i class="ion ion-bag"></i>
              </div>
             
            </div>
          </div>
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-info">
              <div class="inner">
                 <?php 
             //    $con = mysqli_connect("localhost", "root", "", "jibran84_ach");
                 $today = date("Y-m-d");
                 $query = "select count(*) as total from user_status where status = 'Padding'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                ?>
                <h3><?php echo $row['total'];?></h3>
                <p>Total Unpaid User</p>
              </div>
              <div class="icon">
                <i class="ion ion-bag"></i>
              </div>
             
            </div>
          </div>
        </div>
        <!-- /.row -->
        <!-- Main row -->
        <div class="content">
      <div class="container-fluid">
        <div class="row">
        
          <!-- /.col-md-6 -->
          <div class="col-lg-12">
            <div class="card">
              <div class="card-header no-border">
                <div class="d-flex justify-content-between">
                  <h3 class="card-title">Sell Report By Domains Leads</h3>
                  <div class="col-2 pull-right">
                            <select class="form-control" id="customgraph" style="color:white;background-color:#128396">
                            <option value="">Select date</option>
                            <option value="Today">Today</option>
                            <option value="Yesterday">Yesterday</option>
                            <option value="last 7days">Last 7 days</option>
                            <option value="month">Current Month</option>
                            <option value="last month">Last Month</option>
                        </select>
                    </div>
                  <a href="javascript:void(0);" id="sellReport">View Report</a>
                </div>
              </div>
              <div class="card-body" id="graphshowcus">
                 <div class="position-relative mb-4" >
                  <canvas id="visitors-chart1" height="200"></canvas>
                  
                </div>

                <!-- <div id="chart-container">
        <canvas id="graphCanvas"></canvas>
                  </div> -->
                <!-- /.d-flex -->

                
            </div>
            
            <!-- /.card -->

            
          </div>
          <!-- /.col-md-6 -->
        </div>
        <!-- /.row -->
      </div>
     
      <!-- /.container-fluid -->
    </div>
        <!-- /.row (main row) -->
      </div><!-- /.container-fluid -->
    </section>
  
    <!-- /.content -->
  </div>
  
 <script src="plugins/chart.js/Chart.min.js"></script>

    <script>
     $(document).ready(function () {
         $.post("data.php?TotalSellDomain=true",function (data){
                 
                   var Decline = [];
                    var Success = [];
                    var Days = [];
                    for (var i in data) {
                        Decline.push(data[i].NUM);
                        Success.push(data[i].Success);
                        Days.push(data[i].shortname);
                
                        console.log(name);
                        
                    }  
  //get the line chart canvas
  var ctx = $("#visitors-chart1");

  //line chart data
  var data = {
    labels: Days,
    datasets: [
      {
        label: "Sell",
        data: Success,
        backgroundColor: "Green",
        borderColor: "Green",
        fill: false,
        lineTension: 0,
        radius: 5
      },
      {
        label: "Total Leads",
        data: Decline,
        backgroundColor: "skyBlue",
        borderColor: "blue",
        fill: false,
        lineTension: 0,
        radius: 5
      }
    ]
  };

  //options
  var options = {
    responsive: true,
    title: {
      display: true,
      position: "top",
      text: "Line",
      fontSize: 18,
      fontColor: "#111"
    },
    legend: {
      display: true,
      position: "top",
      labels: {
        fontColor: "#333",
        fontSize: 16
      }
    }
  };

  //create Chart class object
  var chart = new Chart(ctx, {
    type: "bar",
    data: data,
    options: options
  });
  
                })
       })
          $("#customgraph").change(function(){
           
            var cus_date= $("#customgraph").val();
          
              $.post("response.php",{cus_date2:cus_date},function(data){
                $("#graphshowcus").html( '');
                $("#graphshowcus").html(data);
              })
          })
</script>
   
  <?php
}elseif($_POST['profile']){
    $id = $_POST['profile'];
    $query = "SELECT user_status.status as Role,user_status.card_type,user_status.req_card_number,new_invoice.*, country.nicename FROM user_status
JOIN new_invoice on new_invoice.id = user_status.user_id
join country on country.iso = new_invoice.country
WHERE user_status.user_id = '$id'";
    $result = mysqli_query($con,$query);
    $rows = mysqli_num_rows($result);
    
    if($rows == 0){
         $query = "Select * from new_invoice where id = '$id'";
         $result = mysqli_query($con,$query);
    }
    
    $row = mysqli_fetch_assoc($result);
    
     if($row['card_type'] == "001"){
        $card = "Visa Card";
    }elseif($row['card_type'] == "002"){
        $card = "Master Card";
    }else{
        $card =$row['card_type'];
    }
    
    ?>
    <div class="card-header">
        <h3 class="card-title">User Profile</h3>
        <a class="btn btn-info float-right" href="pdf.php?id=<?php echo $row['id']?>">Invoice Genrate</a>
    </div>
    <div class="card-body">
               <div class="tab-content">
                  <div class="active tab-pane" id="activity">
                    <!-- Post -->
                    <div class="post">
                      <div class="user-block">
                        <img class="img-circle img-bordered-sm" src="user1-128x128.jpg" alt="user image">
                        <span class="username">
                          <a href="#"><?php echo $row['first']." ".$row['last_name'];?></a>
                          <a href="#" class="float-right btn-tool"><i class="fa fa-times"></i></a>
                        </span>
                        <span class="description">Created At - <?php echo $row['dates'];?></span>
                      </div>
                    </div>
                    <!-- /.post -->
                    <p>
                <ul class="list-group list-group-unbordered mb-3">
                                    <li class="list-group-item">
                    <b>Full Name </b> <a class="float-right"><?php echo $row['first'].$row['last_name']?></a>
                  </li>
                  <li class="list-group-item">
                    <b>Email </b> <a class="float-right"><?php echo $row['pay_to_email']?></a>
                  </li>
                   <li class="list-group-item">
                    <b>Password </b> <a class="float-right"><?php echo $row['passwords']?></a>
                  </li>
                     <li class="list-group-item">
                    <b>Order Id </b> <a class="float-right"><?php echo $row['invoice_id']?></a>
                  </li>
                  <li class="list-group-item">
                    <b>Phone Number </b> <a class="float-right"><?php echo $row['c_number']?></a>
                  </li>
                  <?php 
                  $user_Id =$row['id'];
                  $query2 = "SELECT * FROM `user_ip` where user_id ='$user_Id' ";
                  $result2 = mysqli_query($con,$query2);
                  $row2 = mysqli_fetch_assoc($result2);
                  ?>
                   <li class="list-group-item">
                    <b>IP Address </b> <a class="float-right"><?php echo $row2['user_ip']?></a>
                  </li>
                  <li class="list-group-item">
                    <b>Address </b> <a class="float-right"><?php echo $row['address']?></a>
                  </li>
                   <li class="list-group-item">
                    <b>City </b> <a class="float-right"><?php echo $row['city']?></a>
                  </li>
                  <li class="list-group-item">
                    <b>Zip Code </b> <a class="float-right"><?php echo $row['zip_code']?></a>
                  </li>
                  <li class="list-group-item">
                    <b>Country </b> <a class="float-right"><?php if($row['nicename'] === "" || $row['nicename'] === NULL){
                    echo $row['country'];
                    }else{
                   echo  $row['nicename'];
                    }?></a>
                  </li>
                   <li class="list-group-item">
                    <b>State</b> <a class="float-right"><?php echo $row['state']?></a>
                  </li>
                  <li class="list-group-item">
                    <b>Domain Name</b> <a class="float-right"><?php echo $row['websitename']?></a>
                  </li>
                  <li class="list-group-item">
                    <b>Package</b> <a class="float-right"><?php echo "$".$row['amount']?></a>
                  </li>
                   <li class="list-group-item">
                    <b>Card</b> <a class="float-right"><?php echo $card?></a>
                  </li>
                   <li class="list-group-item">
                    <b>Card Number </b> <a class="float-right"><?php echo $row['req_card_number']?></a>
                  </li>
                   <li class="list-group-item">
                    <b>Status</b> <a class="float-right"><?php if($row['Role'] == 'Success'){
                        echo "Paided*";
                    }else{
                        echo $row['Role'];
                    }?></a>
                  </li>
                </ul>
                    </p>
                   
                </div>
                <!-- /.tab-content -->
              </div>
    
    <?php
    
    
}elseif($_POST['Selected']){
    $arr = $_POST['Selected'];
    
    $emails = implode(",",$arr);
    
    ?>
    
    <div class="card card-outline card-info">
            <div class="card-header">
              <h3 class="card-title">
               Send Email To User:
                <small><?php echo $emailTo; ?></small>
              </h3>
              <!-- tools box -->
              
              <!-- /. tools -->
            </div>
            <!-- /.card-header -->

<div class="card-body">
<form method="POST" action="emailSend.php">
<label>USER EMAIL</label>

<select class="form-control" id="domain" name ="domain">
    <option>Select Domain Users</option>
<?php
     $query = "SELECT DISTINCT(websitename),shortname FROM new_invoice";
    $result = mysqli_query($con,$query);
    while($row = mysqli_fetch_assoc($result)){
        
        if( $row['websitename'] == ""){}else{
    ?>
    <option value="<?php echo $row['shortname']?>"><?php echo $row['websitename'];?></option>
    <?php
        }
    }
    ?>
</select><br>
<select class="form-control" id="template" name="template">
    <option>Select Template</option>
<?php
     $query = "select * from email_template";
    $result = mysqli_query($con,$query);
    while($row = mysqli_fetch_assoc($result)){
    ?>
    <option value="<?php echo $row['id']?>"><?php echo $row['campaign_name'];?></option>
    <?php
    }
    ?>
</select><br>



<input type="hidden" name="emailTo" class="form-control" value="<?php echo $emails; ?>"><br><br>
<div id="showeditor">
    
</div>
<input type="Submit" class="btn btn-success pull-right" name="sendEmail" value="Send">

</form>
              </div>
              
           
          </div>
    <script>
        $(document).ready(function(){
           $("#template").change(function(){
              template = $(this).val();
             $.post('response.php',{template:template},function(data){
                 $("#showeditor").html(data);
             })
           })
        })
    </script>
    <?php
    
}elseif(isset($_POST['template'])){
    $id = $_POST['template'];
    $query = "select * from email_template where id = '$id'";
    $result = mysqli_query($con,$query);
    $row = mysqli_fetch_assoc($result);
    
    
    ?>
    <script type="text/javascript" src="ck/ckeditor.js"></script>

<textarea class="textarea ckeditor" name="art" id="editor"  
style="width: 100%; height: 200px; font-size: 14px; line-height: 18px; border: 1px solid rgb(221, 221, 221); padding: 10px;" 
placeholder="Place some text here"><?php echo $row['template_name']; ?></textarea>
    
    <?php
    
}elseif($_POST['productReport']){
   
    
    ?>

        
        <div class="row">
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-info">
              <div class="inner">
                 <?php 
             //    $con = mysqli_connect("localhost", "root", "", "jibran84_ach");
                 $today = date("Y-m-d");
                 $query = "SELECT count(*) as today FROM user_status
                 join new_invoice on new_invoice.id = user_status.user_id
                 where user_status.created_at = '$today' and user_status.status ='Success'
                 and new_invoice.zee_product = 'PS'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                ?>
                <h3><?php echo $row['today'];?></h3>
                <p>Today Paided User from PS</p>
              </div>
              <div class="icon">
                <i class="ion ion-bag"></i>
              </div>
             
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-success">
              <div class="inner">
                <?php 
                 
                 $today = date("Y-m-d");
                 $query = "SELECT count(*) as week FROM user_status
                          join new_invoice on new_invoice.id = user_status.user_id
                          WHERE user_status.created_at >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY
                          AND   user_status.created_at < curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY
                          and user_status.status = 'Success'
                          and new_invoice.zee_product = 'PS'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 
                ?>

                <h3><?php echo $row['week'];?></h3>

                <p>Last Week Paided Users from PS</p>
              </div>
              <div class="icon">
                <i class="ion ion-stats-bars"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-warning">
              <div class="inner">
                 <?php 
                 
                 $today = date("Y-m-d");
                 $query = "SELECT count(*) as lastMonth FROM user_status
                         join new_invoice on new_invoice.id = user_status.user_id
                        WHERE YEAR(user_status.created_at) = YEAR(CURRENT_DATE - INTERVAL 1 MONTH)
                        AND MONTH(user_status.created_at) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH)
                        and new_invoice.zee_product = 'PS'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 
                ?>
                <h3><?php echo $row['lastMonth'];?></h3>

                <p>Last Month Paided Users From PS</p>
              </div>
              <div class="icon">
                <i class="ion ion-person-add"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-danger">
              <div class="inner">
                <?php 
                 
                 $query = "SELECT  COUNT(*) total FROM user_status
                           join new_invoice on new_invoice.id = user_status.user_id
                         WHERE YEAR(user_status.`created_at`) = YEAR(DATE_SUB(CURDATE(), INTERVAL 1 YEAR)) AND user_status.status='Success' and new_invoice.zee_product = 'PS'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                ?>
                <h3><?php echo $row['total'];?></h3>

                <p>Last Year Paided Users From PS</p>
              </div>
              <div class="icon">
                <i class="ion ion-pie-graph"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
        </div>
        <div class="row">
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box" style="background-color:#7CF944">
              <div class="inner">
                 <?php 
             //    $con = mysqli_connect("localhost", "root", "", "jibran84_ach");
                 $today = date("Y-m-d");
                 $query = "SELECT sum(new_invoice.amount) as total from user_status 
                            join new_invoice on new_invoice.id = user_status.user_id
                            WHERE user_status.status = 'Success'
                            AND user_status.created_at = '$today'
                             and new_invoice.zee_product = 'PS'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 $sell = $row['total'];
                 if($sell == ""){
                     $sell = "0";
                 }
                ?>
                <h3><?php echo "$" .$sell;?></h3>
                <p>Today Sell From Ps</p>
              </div>
              <div class="icon">
               <i class="fa fa-shopping-cart"></i>
              </div>
             
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-info" >
              <div class="inner">
                <?php 
                 
                 $today = date("Y-m-d");
                 $query = "SELECT sum(new_invoice.amount) as total from user_status 
                           join new_invoice on new_invoice.id = user_status.user_id
                           WHERE user_status.created_at >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY
                           AND   user_status.created_at < curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY
                           and user_status.status = 'Success'
                           and new_invoice.zee_product = 'PS'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 
                ?>

                <h3><?php echo "$". $row['total'];?></h3>

                <p>Last Week Sell From PS</p>
              </div>
              <div class="icon">
                <i class="fa fa-money"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box" style="background-color:#E62277">
              <div class="inner">
                 <?php 
                 
                 $today = date("Y-m-d");
                 $query = "SELECT sum(new_invoice.amount) as total from user_status 
       join new_invoice on new_invoice.id = user_status.user_id
        WHERE YEAR(user_status.created_at) = YEAR(CURRENT_DATE - INTERVAL 1 MONTH)
      AND MONTH(user_status.created_at) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH)
       and user_status.status = 'Success'
       and new_invoice.zee_product = 'PS'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 $total = $row['total'];
                
                  if(is_null($total)){
                     $total = "0";
                 }
                 
                 
                ?>
                <h3><?php echo "$".$total?></h3>

                <p>Last Month Sell From PS</p>
              </div>
              <div class="icon">
                <i class="fa  fa-check"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box" style="background-color:#35ACF7">
              <div class="inner">
                <?php 
                 
                 $query = "SELECT sum(new_invoice.amount) as total from user_status 
                           join new_invoice on new_invoice.id = user_status.user_id
                           WHERE YEAR(user_status.`created_at`) = YEAR(DATE_SUB(CURDATE(), INTERVAL 1 YEAR))
                           and user_status.status = 'Success'
                           and new_invoice.zee_product = 'PS'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 $total = $row['total'];
                  if(is_null($total)){
                     $total = "0";
                 }
                ?>
                <h3><?php echo "$".$total;?></h3>

                <p>Last Year Sell From PS</p>
              </div>
              <div class="icon">
                <i class="ion ion-person-add"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
        </div>
         <div class="row">
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-info">
              <div class="inner">
                 <?php 
             //    $con = mysqli_connect("localhost", "root", "", "jibran84_ach");
                 $today = date("Y-m-d");
                 $query = "SELECT sum(new_invoice.amount) as total
                            FROM   user_status
                            join new_invoice on new_invoice.id = user_status.user_id
                            WHERE  YEARWEEK(user_status.`created_at`, 1) = YEARWEEK(CURDATE(), 1)                        
                            and user_status.status = 'Success'
                            and new_invoice.zee_product = 'PS'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 $num_row = mysqli_num_rows($result);
                 $total = $row['total'];
                  if(is_null($total)){
                     $total = "0";
                 }
                ?>
                <h3><?php echo "$".$total;?></h3>
                <p>Current Week Sell Form PS</p>
              </div>
              <div class="icon">
                <i class="ion ion-bag"></i>
              </div>
             
            </div>
          </div>
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-warning">
              <div class="inner">
                 <?php 
             //    $con = mysqli_connect("localhost", "root", "", "jibran84_ach");
                 $today = date("Y-m-d");
                 $query = "SELECT sum(new_invoice.amount) as total
                            FROM  user_status
                            join new_invoice on new_invoice.id = user_status.user_id
                            WHERE MONTH(user_status.`created_at`) = MONTH(CURRENT_DATE())
                            AND YEAR(user_status.`created_at`) = YEAR(CURRENT_DATE())
                            and user_status.status = 'Success'
                            and new_invoice.zee_product = 'PS'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 $num_row = mysqli_num_rows($result);
                 $total = $row['total'];
                
                ?>
                <h3><?php echo "$".$total;?></h3>
                <p>Current Month Sell Form PS</p>
              </div>
              <div class="icon">
                <i class="ion ion-bag"></i>
              </div>
             
            </div>
          </div>
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-danger">
              <div class="inner">
                 <?php 
             //    $con = mysqli_connect("localhost", "root", "", "jibran84_ach");
                 $today = date("Y-m-d");
                 $query = "SELECT SUM(new_invoice.amount) as total FROM user_status
                             JOIN new_invoice on new_invoice.id = user_status.user_id
                             WHERE YEAR(user_status.created_at) = YEAR(CURDATE())
                             AND user_status.status = 'Success'
                             and new_invoice.zee_product = 'PS'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                ?>
                <h3><?php echo "$".$row['total'];?></h3>
                <p>Current Year Sell Form PS</p>
              </div>
              <div class="icon">
                <i class="ion ion-bag"></i>
              </div>
             
            </div>
          </div>
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-info">
              <div class="inner">
                 <?php 
             //    $con = mysqli_connect("localhost", "root", "", "jibran84_ach");
                 $today = date("Y-m-d");
                 $query = "select count(*) as total from user_status
                 JOIN new_invoice on new_invoice.id = user_status.user_id
                 where user_status.status = 'Padding'
                 and new_invoice.zee_product = 'PS'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                ?>
                <h3><?php echo $row['total'];?></h3>
                <p>Total Unpaid User</p>
              </div>
              <div class="icon">
                <i class="ion ion-bag"></i>
              </div>
             
            </div>
          </div>
        </div>
          <div class="content">
      <div class="container-fluid">
        <div class="row">
        
          <!-- /.col-md-6 -->
          <div class="col-lg-12">
            <div class="card">
              <div class="card-header no-border">
                <div class="d-flex justify-content-between">
                  <h3 class="card-title">Sell Report By Domains Leads</h3>
                  <a href="javascript:void(0);" id="sellReport">View Report</a>
                </div>
              </div>
              <div class="card-body">
                 <div class="position-relative mb-4">
                  <canvas id="visitors-chart1" height="200"></canvas>
                </div>

                <!-- <div id="chart-container">
        <canvas id="graphCanvas"></canvas>
                  </div> -->
                <!-- /.d-flex -->

                
            </div>
            <!-- /.card -->

            
          </div>
          <!-- /.col-md-6 -->
        </div>
        <!-- /.row -->
      </div>
     
      <!-- /.container-fluid -->
    </div>
        <!-- /.row (main row) -->
      </div><!-- /.container-fluid -->
         <script>
     $(document).ready(function () {
         $.post("data.php?TotalSellDomainPS=true",function (data){
                 
                   var Decline = [];
                    var Success = [];
                    var Days = [];
                    for (var i in data) {
                        Decline.push(data[i].NUM);
                        Success.push(data[i].Success);
                        Days.push(data[i].shortname);
                
                        console.log(name);
                        
                    }  
  //get the line chart canvas
  var ctx = $("#visitors-chart1");

  //line chart data
  var data = {
    labels: Days,
    datasets: [
      {
        label: "Sell",
        data: Success,
        backgroundColor: "Green",
        borderColor: "Green",
        fill: false,
        lineTension: 0,
        radius: 5
      },
      {
        label: "Total Leads",
        data: Decline,
        backgroundColor: "skyBlue",
        borderColor: "blue",
        fill: false,
        lineTension: 0,
        radius: 5
      }
    ]
  };

  //options
  var options = {
    responsive: true,
    title: {
      display: true,
      position: "top",
      text: "Line",
      fontSize: 18,
      fontColor: "#111"
    },
    legend: {
      display: true,
      position: "top",
      labels: {
        fontColor: "#333",
        fontSize: 16
      }
    }
  };

  //create Chart class object
  var chart = new Chart(ctx, {
    type: "bar",
    data: data,
    options: options
  });
  
                })
       })
    
    
      

        
        </script>
        <?php
}elseif($_POST['productDecline']){
     $query = "SELECT new_invoice.`pay_to_email`,new_invoice.`dates`,new_invoice.`amount`,new_invoice.`invoice_id`,new_invoice.`country`,user_status.`status` FROM user_status
                    JOIN new_invoice ON new_invoice.`id` = user_status.`user_id` WHERE user_status.`status` = 'Decline'
                    and new_invoice.zeeproduct = 'PS'";
         $result = mysqli_query($con,$query);

                ?>
              <table id="example6" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Email</th>
                  <th>Invoice Id</th>
                  <th>Amount</th>
                  <th>Country</th>
                  <th>Date</th>
                  <th>Status</th>
                  <th>Action</th>
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                  <td class="sorting_1"><?php echo $row['pay_to_email'];?></td>
                  <td><?php echo $row['invoice_id']?></td>
                  <td><?php echo $row['amount']?></td>
                  <td><?php echo $row['country']?></td>
                  <td><?php echo $row['dates']?></td>
                  <td><?php echo $row['status']?></td>
                  <td><a class="btn btn-danger" data-value="<?php echo $row['pay_to_email']?>" style="color:white" id="emailTo">Send Email</a></td>
                </tr>
                <?php } ?>
                 </tbody>              
              </table>
              <script type="text/javascript">
              	$(document).ready(function() {
				    $('#example6').DataTable( {
				        paging: true,
					   pageLength: 10,
				    });
				});
              </script>

              <?php
	
}elseif($_POST['productcancel']){
     $query = "SELECT new_invoice.`pay_to_email`,new_invoice.`dates`,new_invoice.`amount`,new_invoice.`invoice_id`,new_invoice.`country`,user_status.`status` FROM user_status
                    JOIN new_invoice ON new_invoice.`id` = user_status.`user_id` WHERE user_status.`status` = 'Cancel'
                    and new_invoice.zeeproduct = 'PS'";
         $result = mysqli_query($con,$query);

                ?>
              <table id="example6" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Email</th>
                  <th>Invoice Id</th>
                  <th>Amount</th>
                  <th>Country</th>
                  <th>Date</th>
                  <th>Status</th>
                  <th>Action</th>
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                  <td class="sorting_1"><?php echo $row['pay_to_email'];?></td>
                  <td><?php echo $row['invoice_id']?></td>
                  <td><?php echo $row['amount']?></td>
                  <td><?php echo $row['country']?></td>
                  <td><?php echo $row['dates']?></td>
                  <td><?php echo $row['status']?></td>
                  <td><a class="btn btn-danger" data-value="<?php echo $row['pay_to_email']?>" style="color:white" id="emailTo">Send Email</a></td>
                </tr>
                <?php } ?>
                 </tbody>              
              </table>
              <script type="text/javascript">
              	$(document).ready(function() {
				    $('#example6').DataTable( {
				        paging: true,
					   pageLength: 10,
				    });
				});
              </script>

              <?php
	
}elseif($_POST['productpending']){
     $query = "SELECT new_invoice.`pay_to_email`,new_invoice.`dates`,new_invoice.`amount`,new_invoice.`invoice_id`,new_invoice.`country`,user_status.`status` FROM user_status
                    JOIN new_invoice ON new_invoice.`id` = user_status.`user_id` WHERE user_status.`status` = 'pending'
                    and new_invoice.zeeproduct = 'PS'";
         $result = mysqli_query($con,$query);

                ?>
              <table id="example6" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Email</th>
                  <th>Invoice Id</th>
                  <th>Amount</th>
                  <th>Country</th>
                  <th>Date</th>
                  <th>Status</th>
                  <th>Action</th>
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                  <td class="sorting_1"><?php echo $row['pay_to_email'];?></td>
                  <td><?php echo $row['invoice_id']?></td>
                  <td><?php echo $row['amount']?></td>
                  <td><?php echo $row['country']?></td>
                  <td><?php echo $row['dates']?></td>
                  <td><?php echo $row['status']?></td>
                  <td><a class="btn btn-danger" data-value="<?php echo $row['pay_to_email']?>" style="color:white" id="emailTo">Send Email</a></td>
                </tr>
                <?php } ?>
                 </tbody>              
              </table>
              <script type="text/javascript">
              	$(document).ready(function() {
				    $('#example6').DataTable( {
				        paging: true,
					   pageLength: 10,
				    });
				});
              </script>

              <?php
	
}elseif($_POST['productpaid']){
     $query = "SELECT new_invoice.`pay_to_email`,new_invoice.`dates`,new_invoice.`amount`,new_invoice.`invoice_id`,new_invoice.`country`,user_status.`status` FROM user_status
                    JOIN new_invoice ON new_invoice.`id` = user_status.`user_id` WHERE user_status.`status` = 'Success'
                    and new_invoice.zeeproduct = 'PS'";
         $result = mysqli_query($con,$query);

                ?>
              <table id="example6" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Email</th>
                  <th>Invoice Id</th>
                  <th>Amount</th>
                  <th>Country</th>
                  <th>Date</th>
                  <th>Status</th>
                  <th>Action</th>
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                  <td class="sorting_1"><?php echo $row['pay_to_email'];?></td>
                  <td><?php echo $row['invoice_id']?></td>
                  <td><?php echo $row['amount']?></td>
                  <td><?php echo $row['country']?></td>
                  <td><?php echo $row['dates']?></td>
                  <td><?php echo $row['status']?></td>
                  <td><a class="btn btn-danger" data-value="<?php echo $row['pay_to_email']?>" style="color:white" id="emailTo">Send Email</a></td>
                </tr>
                <?php } ?>
                 </tbody>              
              </table>
              <script type="text/javascript">
              	$(document).ready(function() {
				    $('#example6').DataTable( {
				       paging    : true,
					   pageLength: 10,
				    });
				});
              </script>

              <?php
	
}elseif(isset($_POST['notiView'])){
    $id  = $_POST['notiView'];
    $query = "update notification set  veiw = '1' where id = $id";
    $result = mysqli_query($con,$query);
    
     $query  = "SELECT * from notification where id = $id";
        $result = mysqli_query($con,$query);
        $row = mysqli_fetch_assoc($result);
     $id  = $row['user_id'];
     $message  = $row['message'];
     $query = "SELECT user_status.status as Role,user_status.card_type,user_status.req_card_number,new_invoice.*, country.nicename FROM user_status
                JOIN new_invoice on new_invoice.id = user_status.user_id
                join country on country.iso = new_invoice.country
                WHERE user_status.user_id = '$id'";
    $result = mysqli_query($con,$query);
    $rows = mysqli_num_rows($result);
    
    if($rows == 0){
         $query = "Select * from new_invoice where id = '$id'";
         $result = mysqli_query($con,$query);
    }
    
    $row = mysqli_fetch_assoc($result);
    
    if($row['card_type'] == "001"){
        $card = "Visa Card";
    }elseif($row['card_type'] == "002"){
        $card = "Master Card";
    }else{
        $card =$row['card_type'];
    }
    ?>
   <div class="row">
        <div class="col-12">
         

          <!-- /.card -->

        <div class="card">
            <div class="card-header">
               <h3 class="card-title">User Profile Who's Status <?php echo $message?></h3>

            </div>
    <div class="card-body">
                <div class="tab-content">
                  <div class="active tab-pane" id="activity">
                    <!-- Post -->
                    <div class="post">
                      <div class="user-block">
                        <img class="img-circle img-bordered-sm" src="user1-128x128.jpg" alt="user image">
                        <span class="username">
                          <a href="#"><?php echo $row['first']." ".$row['last_name'];?></a>
                          <a href="#" class="float-right btn-tool"><i class="fa fa-times"></i></a>
                        </span>
                        <span class="description">Created At - <?php echo $row['dates'];?></span>
                      </div>
                    </div>
                    <!-- /.post -->
                    <p>
                <ul class="list-group list-group-unbordered mb-3">
                                    <li class="list-group-item">
                    <b>Full Name </b> <a class="float-right"><?php echo $row['first'].$row['last_name']?></a>
                  </li>
                  <li class="list-group-item">
                    <b>Email </b> <a class="float-right"><?php echo $row['pay_to_email']?></a>
                  </li>
                   <li class="list-group-item">
                    <b>Password </b> <a class="float-right"><?php echo $row['passwords']?></a>
                  </li>
                   <li class="list-group-item">
                    <b>Order Id </b> <a class="float-right"><?php echo $row['invoice_id']?></a>
                  </li>
                  <li class="list-group-item">
                    <b>Phone Number </b> <a class="float-right"><?php echo $row['c_number']?></a>
                  </li>
                  <?php 
                  $user_Id =$row['id'];
                  $query2 = "SELECT * FROM `user_ip` where user_id ='$user_Id' ";
                  $result2 = mysqli_query($con,$query2);
                  $row2 = mysqli_fetch_assoc($result2);
                  ?>
                   <li class="list-group-item">
                    <b>IP Address </b> <a class="float-right"><?php echo $row2['user_ip']?></a>
                  </li>
                  <li class="list-group-item">
                    <b>Address </b> <a class="float-right"><?php echo $row['address']?></a>
                  </li>
                   <li class="list-group-item">
                    <b>City </b> <a class="float-right"><?php echo $row['city']?></a>
                  </li>
                  <li class="list-group-item">
                    <b>Zip Code </b> <a class="float-right"><?php echo $row['zip_code']?></a>
                  </li>
                  <li class="list-group-item">
                    <b>Country </b> <a class="float-right"><?php if($row['nicename'] === "" || $row['nicename'] === NULL){
                    echo $row['country'];
                    }else{
                   echo  $row['nicename'];
                    }?></a>
                  </li>
                  <li class="list-group-item">
                    <b>Domain Name</b> <a class="float-right"><?php echo $row['websitename']?></a>
                  </li>
                  <li class="list-group-item">
                    <b>Package</b> <a class="float-right"><?php echo "$".$row['amount']?></a>
                  </li>
                   <li class="list-group-item">
                    <b>Card</b> <a class="float-right"><?php echo $card?></a>
                  </li>
                   <li class="list-group-item">
                    <b>Card Number </b> <a class="float-right"><?php echo $row['req_card_number']?></a>
                  </li>
                   <li class="list-group-item">
                    <b>Status</b> <a class="float-right"><?php if($row['Role'] == 'Success'){
                        echo "Paided*";
                    }else{
                        echo $row['Role'];
                    }?></a>
                  </li>
                </ul>
                    </p>
                   
                </div>
                <!-- /.tab-content -->
              </div>
                </div>
</div>
    
    <?php
    
    
}elseif(isset($_POST['notification'])){
    ?>
           <a class="nav-link" data-toggle="dropdown" id="stop" href="#" aria-expanded="false">
          <i class="fa fa-ban" title="Decline"></i>
           <?php
        $query  = "SELECT count(*) as total from notification where veiw = 0 and message = 'DECLINE'";
        $result = mysqli_query($con,$query);
        $row = mysqli_fetch_assoc($result);
        $num = mysqli_num_rows($result);
        if($row['total'] > 0){
        ?>
          <span class="badge badge-danger navbar-badge"><?php echo $row['total']?></span>
          <?php
          }
          ?>
        </a>
        <div class="dropdown-menu dropdown-menu-lg dropdown-menu-right">
        
        <?php
        $query  = "SELECT new_invoice.*,notification.message,notification.create_at,notification.id as notiid FROM notification
                    JOIN new_invoice on new_invoice.id = notification.user_id
                    where notification.veiw = 0
                    and notification.message = 'DECLINE'  order by notification.id desc limit 0,10";
        $result = mysqli_query($con,$query);
        while($row = mysqli_fetch_assoc($result)){
            $create = $row['create_at'];
            $datetime = date("Y-m-d H:i:s");
            $datetime1 = new DateTime($create);
            $datetime2 = new DateTime();
            $interval = $datetime1->diff($datetime2);
        ?>
        
          <a  class="dropdown-item notificationView" data-value="<?php echo $row['notiid']?>">
            <!-- Message Start -->
            <div class="media">
              <img src="dist/img/user8-128x128.jpg" alt="User Avatar" class="img-size-50 img-circle mr-3">
              <div class="media-body">
                <h3 class="dropdown-item-title">
                  <?php echo $row['first']." ".$row['last_name']?>
                  <span class="float-right text-sm text-muted"><i class="fa fa-star"></i></span>
                </h3>
                <p class="text-sm">New Sell <?php echo $row['message']?></p>
                <p class="text-sm text-muted"><i class="fa fa-clock-o mr-1"></i><?php echo  $interval->format('%a days, %H hours, %I min');?> hour Ago </p>
              </div>
            </div>
            <!-- Message End -->
          </a>
          <div class="dropdown-divider"></div>
          <?php
                }
          ?>
           <a href="#" class="dropdown-item dropdown-footer seeall">See All Messages</a>
        </div>
          <script>
              $(".notificationView").click(function(){
    
    var notiView = $(this).data("value");
    
    $.post("response.php",{notiView:notiView},function(data){
        
        $("#homeDAta").html(data);
    })
})
          </script>
        <?php
    
}elseif(isset($_POST['notification2'])){
    ?>
           <a class="nav-link" data-toggle="dropdown" id="stop" href="#" aria-expanded="false">
          <i class="fa fa-comments-o" title="Pending"></i>
           <?php
        $query  = "SELECT count(*) as total from notification where veiw = 0 and message = 'Pending'";
        $result = mysqli_query($con,$query);
        $row = mysqli_fetch_assoc($result);
        $num = mysqli_num_rows($result);
        if($row['total'] > 0){
        ?>
          <span class="badge badge-danger navbar-badge"><?php echo $row['total']?></span>
          <?php
          }
          ?>
        </a>
        <div class="dropdown-menu dropdown-menu-lg dropdown-menu-right">
        
        <?php
        $query  = "SELECT new_invoice.*,notification.message,notification.create_at,notification.id as notiid FROM notification
                    JOIN new_invoice on new_invoice.id = notification.user_id
                    where notification.veiw = 0
                    and notification.message = 'Pending' order by notification.id desc limit 0,10";
        $result = mysqli_query($con,$query);
        while($row = mysqli_fetch_assoc($result)){
            $create = $row['create_at'];
            $$datetime = date("Y-m-d H:i:s");
            $datetime1 = new DateTime($create);
            $datetime2 = new DateTime();
            $interval = $datetime1->diff($datetime2);
        ?>
        
          <a  class="dropdown-item notificationView" data-value="<?php echo $row['notiid']?>">
            <!-- Message Start -->
            <div class="media">
              <img src="dist/img/user8-128x128.jpg" alt="User Avatar" class="img-size-50 img-circle mr-3">
              <div class="media-body">
                <h3 class="dropdown-item-title">
                  <?php echo $row['first']." ".$row['last_name']?>
                  <span class="float-right text-sm text-muted"><i class="fa fa-star"></i></span>
                </h3>
                <p class="text-sm">New Sell <?php echo $row['message']?></p>
                <p class="text-sm text-muted"><i class="fa fa-clock-o mr-1"></i><?php echo  $interval->format('%a days, %H hours, %I min');?> hour Ago </p>
              </div>
            </div>
            <!-- Message End -->
          </a>
          <div class="dropdown-divider"></div>
          <?php
                }
          ?>
           <a href="#" class="dropdown-item dropdown-footer seeall">See All Messages</a>
        </div>
          <script>
              $(".notificationView").click(function(){
    
    var notiView = $(this).data("value");
    
    $.post("response.php",{notiView:notiView},function(data){
        
        $("#homeDAta").html(data);
    })
})
          </script>
        <?php
    
}elseif(isset($_POST['notification3'])){
    ?>
           <a class="nav-link" data-toggle="dropdown" id="stop" href="#" aria-expanded="false">
          <i class="fa fa-bell-o" title="Success"></i>
           <?php
        $query  = "SELECT count(*) as total from notification where veiw = 0 and message = 'Success'";
        $result = mysqli_query($con,$query);
        $row = mysqli_fetch_assoc($result);
        $num = mysqli_num_rows($result);
        if($row['total'] > 0){
        ?>
          <span class="badge badge-danger navbar-badge"><?php echo $row['total']?></span>
          <?php
          }
          ?>
        </a>
        <div class="dropdown-menu dropdown-menu-lg dropdown-menu-right">
        
        <?php
        $query  = "SELECT new_invoice.*,notification.message,notification.create_at,notification.id as notiid FROM notification
                    JOIN new_invoice on new_invoice.id = notification.user_id
                    where notification.veiw = 0
                    and notification.message = 'Success' order by notification.id desc limit 0,10";
        $result = mysqli_query($con,$query);
        while($row = mysqli_fetch_assoc($result)){
            $create = $row['create_at'];
            $datetime = date("Y-m-d H:i:s");
            $datetime1 = new DateTime($create);
            $datetime2 = new DateTime();
            $interval = $datetime1->diff($datetime2);
        ?>
        
          <a  class="dropdown-item notificationView" data-value="<?php echo $row['notiid']?>">
            <!-- Message Start -->
            <div class="media">
              <img src="dist/img/user8-128x128.jpg" alt="User Avatar" class="img-size-50 img-circle mr-3">
              <div class="media-body">
                <h3 class="dropdown-item-title">
                  <?php echo $row['first']." ".$row['last_name']?>
                  <span class="float-right text-sm text-muted"><i class="fa fa-star"></i></span>
                </h3>
                <p class="text-sm">New Sell <?php echo $row['message']?></p>
                <p class="text-sm text-muted"><i class="fa fa-clock-o mr-1"></i><?php echo  $interval->format('%a days, %H hours, %I min');?> hour Ago </p>
              </div>
            </div>
            <!-- Message End -->
          </a>
          <div class="dropdown-divider"></div>
          <?php
                }
          ?>
           <a href="#" class="dropdown-item dropdown-footer seeall">See All Messages</a>
        </div>
          <script>
              $(".notificationView").click(function(){
    
    var notiView = $(this).data("value");
    
    $.post("response.php",{notiView:notiView},function(data){
        
        $("#homeDAta").html(data);
    })
})
          </script>
        <?php
    
}elseif(isset($_POST['allMsg'])){
    ?>
        <div class="card direct-chat direct-chat-primary">
              <div class="card-header ui-sortable-handle" style="cursor: move;">
                <h3 class="card-title">Direct Chat</h3>

                <div class="card-tools">
                
                  <button type="button" class="btn btn-tool" data-widget="collapse">
                    <i class="fa fa-minus"></i>
                  </button>
                
                  <button type="button" class="btn btn-tool" data-widget="remove"><i class="fa fa-times"></i>
                  </button>
                </div>
              </div>
              <!-- /.card-header -->
              <div class="card-body">
                  <div class = "row">
               <div class ="col-lg-2"></div>
                  <div class ="col-lg-8">
                      <br>
        <a class="btn btn-default">Success</a><br>
                      <?php 
        $query  = "SELECT new_invoice.*,notification.message,notification.create_at,notification.id as notiid FROM notification
                    JOIN new_invoice on new_invoice.id = notification.user_id
                    where notification.message = 'Success'
                    order by notification.user_id Desc limit 0,10";
        $result = mysqli_query($con,$query);
        $num = mysqli_num_rows($result);
        if($num > 0){
        while($row = mysqli_fetch_assoc($result)){
            $create = $row['create_at'];
            $datetime1 = new DateTime($create);
            $datetime2 = new DateTime();
            $interval = $datetime1->diff($datetime2);
           $interval->format('%a days, %H hours, %I min and %S sec  ');
                      ?>
     <a  class="dropdown-item notificationView" data-value="<?php echo $row['notiid']?>">
            <!-- Message Start -->
            <div class="media">
              <img src="dist/img/user8-128x128.jpg" alt="User Avatar" class="img-size-50 img-circle mr-3">
              <div class="media-body">
                <h3 class="dropdown-item-title">
                  <?php echo $row['first']." ".$row['last_name']?>
                  <span class="float-right text-sm text-muted"><i class="fa fa-star"></i></span>
                </h3>
                <p class="text-sm">New Sell <?php echo $row['message']?></p>
                <p class="text-sm text-muted"><i class="fa fa-clock-o mr-1"></i><?php echo $interval->format('%a days, %H hours, %I min and %S sec  ');?> hour Ago </p>
              </div>
            </div>
            <!-- Message End -->
          </a>
          <div class="dropdown-divider"></div>
                 <?php
                 }
        }else{
            ?>
                <h5>
                No Success Notification
                </h5>
         
              <?php
        }
                 ?>
                  <br>
        <a class="btn btn-default">Decline</a><br>
                      <?php 
        $query  = "SELECT new_invoice.*,notification.message,notification.create_at,notification.id as notiid FROM notification
                    JOIN new_invoice on new_invoice.id = notification.user_id
                    where notification.message = 'DECLINE'
                    order by notification.user_id Desc limit 0,10";
        $result = mysqli_query($con,$query);
       $num = mysqli_num_rows($result);
        if($num > 0){
        while($row = mysqli_fetch_assoc($result)){
            $create = $row['create_at'];
            $datetime = date("Y-m-d H:i:s");
            $datetime1 = new DateTime($create);
            $datetime2 = new DateTime();
            $interval = $datetime1->diff($datetime2);
         
                      ?>
     <a  class="dropdown-item notificationView" data-value="<?php echo $row['notiid']?>">
            <!-- Message Start -->
            <div class="media">
              <img src="dist/img/user8-128x128.jpg" alt="User Avatar" class="img-size-50 img-circle mr-3">
              <div class="media-body">
                <h3 class="dropdown-item-title">
                  <?php echo $row['first']." ".$row['last_name']?>
                  <span class="float-right text-sm text-muted"><i class="fa fa-star"></i></span>
                </h3>
                <p class="text-sm">New Sell <?php echo $row['message']?></p>
                <p class="text-sm text-muted"><i class="fa fa-clock-o mr-1"></i><?php echo $interval->format('%a days, %H hours, %I min and %S sec  ');?> hour Ago </p>
              </div>
            </div>
            <!-- Message End -->
          </a>
          <div class="dropdown-divider"></div>
                 <?php
                 }
        }else{
            ?>
                <h5>
                No Decline Notification
                </h5>
         
              <?php
        }
                 ?>
                  <br>
        <a class="btn btn-default">Pending</a><br>
                      <?php 
        $query  = "SELECT new_invoice.*,notification.message,notification.create_at,notification.id as notiid FROM notification
                    JOIN new_invoice on new_invoice.id = notification.user_id
                    where notification.message = 'Pending'
                    order by notification.user_id Desc limit 0,10";
        $result = mysqli_query($con,$query);
       $num = mysqli_num_rows($result);
        if($num > 0){
        while($row = mysqli_fetch_assoc($result)){
            $create = $row['create_at'];
            $datetime1 = new DateTime($create);
            $datetime2 = new DateTime();
            $interval = $datetime1->diff($datetime2);
           
                      ?>
     <a  class="dropdown-item notificationView" data-value="<?php echo $row['notiid']?>">
            <!-- Message Start -->
            <div class="media">
              <img src="dist/img/user8-128x128.jpg" alt="User Avatar" class="img-size-50 img-circle mr-3">
              <div class="media-body">
                <h3 class="dropdown-item-title">
                  <?php echo $row['first']." ".$row['last_name']?>
                  <span class="float-right text-sm text-muted"><i class="fa fa-star"></i></span>
                </h3>
                <p class="text-sm">New Sell <?php echo $row['message']?></p>
                <p class="text-sm text-muted"><i class="fa fa-clock-o mr-1"></i><?php echo $interval->format('%a days, %H hours, %I min and %S sec  ');?> hour Ago </p>
              </div>
            </div>
            <!-- Message End -->
          </a>
          <div class="dropdown-divider"></div>
                 <?php
                 }
        }else{
            ?>
                <h5>
                No Pending Notification
                </h5>
         
              <?php
        }
                 ?>
               
                  </div>
                <div class ="col-lg-2"></div>
               </div>
              </div>
              <!-- /.card-body -->
            
            </div>   
            <script>
                $(".notificationView").click(function(){
    
    var notiView = $(this).data("value");
    
    $.post("response.php",{notiView:notiView},function(data){
        
        $("#homeDAta").html(data);
    })
})
            </script>
    <?php
    
}elseif (isset($_POST['TodayLeads'])) {
    $date = date("Y-m-d");
         $query = "SELECT * FROM new_invoice where dates = '$date'";
         $result = mysqli_query($con,$query);

                ?>
     <div class="card">
            <div class="card-header">
               <h3 class="card-title" id="cardData">Today Leads
                <a class="btn btn-info pull-right" style="color:white" id="TodayLeadsSreach">search</a> 
                <a class="btn btn-info pull-right" ><div id="reportrange" style="color:blue">
                  <i class="fa fa-calendar"></i>&nbsp;
                  <span></span> <i class="fa fa-caret-down"></i>
              </div></a> </h3>
            </div>
    <div class="card-body">
              <table id="example6" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Email</th>
                  <th>Website</th>
                  <th>Invoice Id</th>
                  <th>Amount</th>
                  <th>Country</th>
                  <th>Date</th>
                 
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                  <td class="sorting_1"><?php echo $row['pay_to_email'];?></td>
                  <td><?php echo $row['websitename']?></td>
                  <td><?php echo $row['invoice_id']?></td>
                  <td><?php echo $row['amount']?></td>
                  <td><?php echo $row['country']?></td>
                  <td><?php echo $row['dates']?></td>
                 
                </tr>
                <?php } ?>
                 </tbody>              
              </table>
              </div>
              </div>
              <script type="text/javascript">
              	$(document).ready(function() {
				    $('#example6').DataTable( {
				        paging: true,
					   pageLength: 10,
				    });
				});
				$(function() {

    var start = moment().subtract(29, 'days');
    var end   = moment();

    function cb(start, end) {
        $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
    }

    $('#reportrange').daterangepicker({
        startDate: start,
        endDate: end,
        ranges: {
           'Today': [moment(), moment()],
           'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
           'Last 7 Days': [moment().subtract(6, 'days'), moment()],
           'Last 30 Days': [moment().subtract(29, 'days'), moment()],
           'This Month': [moment().startOf('month'), moment().endOf('month')],
           'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
        }
    }, cb);

    cb(start, end);

    

});
              </script>

              <?php
	
}elseif (isset($_POST['TodayLeadsSreach'])) {
        
       $date  = $_POST['TodayLeadsSreach'];
       $array = explode("-", $date);

$date1 = $array[0];
$timestamp = strtotime($date1);
$newDate = date('Y-m-d', $timestamp); 

 $date2 = $array[1];
$timestamp2 = strtotime($date2);
$newDate2 = date('Y-m-d', $timestamp2); 

$query = "SELECT * FROM new_invoice WHERE dates >= '$newDate' AND dates <= '$newDate2' order by id Desc";
	
$result = mysqli_query($con,$query);

                ?>
              <table id="example7" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Email</th>
                  <th>Website</th>
                  <th>Invoice Id</th>
                  <th>Amount</th>
                  <th>Country</th>
                 
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                  <td class="sorting_1"><?php echo $row['pay_to_email'];?></td>
                  <td><?php echo $row['websitename']?></td>
                  <td><?php echo $row['invoice_id']?></td>
                  <td><?php echo $row['amount']?></td>
                  <td><?php echo $row['country']?></td>
                </tr>
                <?php } ?>
                 </tbody>              
              </table>
              
              <script type="text/javascript">
              	$(document).ready(function() {
				    $('#example7').DataTable( {
				        paging: true,
					   pageLength: 10,
				    });
				});
              </script>
			
              <?php
	

}elseif (isset($_POST['todayLeadsSell'])) {
    $date = date("Y-m-d");
         $query = "SELECT new_invoice.* from user_status
                    join new_invoice on  new_invoice.id= user_status.user_id
                    WHERE user_status.status = 'Success'
                    and new_invoice.dates = '$date'";
         $result = mysqli_query($con,$query);

                ?>
     <div class="card">
            <div class="card-header">
               <h3 class="card-title" id="cardData">Today Leads
                <a class="btn btn-info pull-right" style="color:white" id="TodaySellSreach">search</a> 
                <a class="btn btn-info pull-right" ><div id="reportrange" style="color:blue">
                  <i class="fa fa-calendar"></i>&nbsp;
                  <span></span> <i class="fa fa-caret-down"></i>
              </div></a> </h3>
            </div>
    <div class="card-body">
              <table id="example6" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Email</th>
                  <th>Website</th>
                  <th>Invoice Id</th>
                  <th>Amount</th>
                  <th>Country</th>
                  <th>Date</th>
                 
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                  <td class="sorting_1"><?php echo $row['pay_to_email'];?></td>
                  <td><?php echo $row['websitename']?></td>
                  <td><?php echo $row['invoice_id']?></td>
                  <td><?php echo $row['amount']?></td>
                  <td><?php echo $row['country']?></td>
                  <td><?php echo $row['dates']?></td>
                 
                </tr>
                <?php } ?>
                 </tbody>              
              </table>
              </div>
              </div>
              <script type="text/javascript">
              	$(document).ready(function() {
				    $('#example6').DataTable( {
				        paging: true,
					   pageLength: 10,
				    });
				});
				$(function() {

    var start = moment().subtract(29, 'days');
    var end   = moment();

    function cb(start, end) {
        $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
    }

    $('#reportrange').daterangepicker({
        startDate: start,
        endDate: end,
        ranges: {
           'Today': [moment(), moment()],
           'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
           'Last 7 Days': [moment().subtract(6, 'days'), moment()],
           'Last 30 Days': [moment().subtract(29, 'days'), moment()],
           'This Month': [moment().startOf('month'), moment().endOf('month')],
           'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
        }
    }, cb);

    cb(start, end);

    

});
              </script>

              <?php
	
}elseif (isset($_POST['TodaySellSreach'])) {
        
       $date  = $_POST['TodaySellSreach'];
       $array = explode("-", $date);

$date1 = $array[0];
$timestamp = strtotime($date1);
$newDate = date('Y-m-d', $timestamp); 

 $date2 = $array[1];
$timestamp2 = strtotime($date2);
$newDate2 = date('Y-m-d', $timestamp2); 

 $query = "SELECT new_invoice.* from user_status
                    join new_invoice on  new_invoice.id= user_status.user_id
                    WHERE user_status.status = 'Success'
                and new_invoice.dates >= '$newDate' AND  new_invoice.dates <= '$newDate2'";
	
$result = mysqli_query($con,$query);

                ?>
            
                <div class="card">
            <div class="card-header">
               <h3 class="card-title" id="cardData">Today Leads
                <a class="btn btn-info pull-right" style="color:white" id="TodaySellSreach">search</a> 
                <a class="btn btn-info pull-right" ><div id="reportrange" style="color:blue">
                  <i class="fa fa-calendar"></i>&nbsp;
                  <span></span> <i class="fa fa-caret-down"></i>
              </div></a> </h3>
            </div>
    <div class="card-body">
              <table id="example6" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Email</th>
                  <th>Website</th>
                  <th>Invoice Id</th>
                  <th>Amount</th>
                  <th>Country</th>
                  <th>Date</th>
                 
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                  <td class="sorting_1"><?php echo $row['pay_to_email'];?></td>
                  <td><?php echo $row['websitename']?></td>
                  <td><?php echo $row['invoice_id']?></td>
                  <td><?php echo $row['amount']?></td>
                  <td><?php echo $row['country']?></td>
                  <td><?php echo $row['dates']?></td>
                 
                </tr>
                <?php } ?>
                 </tbody>              
              </table>
              </div>
              </div>
              <script type="text/javascript">
              	$(document).ready(function() {
				    $('#example6').DataTable( {
				        paging: true,
					   pageLength: 10,
				    });
				});
				$(function() {

    var start = moment().subtract(29, 'days');
    var end   = moment();

    function cb(start, end) {
        $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
    }

    $('#reportrange').daterangepicker({
        startDate: start,
        endDate: end,
        ranges: {
           'Today': [moment(), moment()],
           'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
           'Last 7 Days': [moment().subtract(6, 'days'), moment()],
           'Last 30 Days': [moment().subtract(29, 'days'), moment()],
           'This Month': [moment().startOf('month'), moment().endOf('month')],
           'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
        }
    }, cb);

    cb(start, end);

    

});
              </script>
              <?php
	

}elseif (isset($_POST['addDispute'])) {
    ?>
            <div class="card card-primary">
              <div class="card-header">
                <h3 class="card-title">Add New Dispute</h3>
              </div>
              <!-- /.card-header -->
              <!-- form start -->
              <form role="form" action="response.php" method="POST" enctype="multipart/form-data">
                <div class="card-body">
                  <div class="row">
                     <div class="col-lg-6">
                        <div class="form-group">
                        <label for="exampleInputEmail1">Email address</label>
                        <input type="email" class="form-control" name="email" id="userEmailDispute" placeholder="Enter email">
                        </div>
                     </div>
                     <div class="col-lg-6">
                          <div class="form-group">
                            <label for="exampleInputEmail1">Bank</label>
                            <input type="text" class="form-control" name="bank" id="bank" placeholder="Enter Bank ">
                          </div>
                     </div>
                 </div>
                  <div class="row">
                     <div class="col-lg-6">
                        <div class="form-group">
                        <label for="exampleInputEmail1">Dispute Date</label>
                        <input type="date" class="form-control" name="dispute_date">
                        </div>
                     </div>
                     <div class="col-lg-6">
                          <div class="form-group">
                            <label for="exampleInputEmail1">Last Date</label>
                            <input type="date" class="form-control" name="last_date">
                          </div>
                     </div>
                 </div>
                  <div class="row">
                     <div class="col-lg-6">
                        <div class="form-group">
                        <label for="exampleInputEmail1">Bank File Attach</label>
                        <input type="file" class="form-control" name="bank_file[]" multiple>
                        </div>
                     </div>
                     <div class="col-lg-6">
                          <div class="form-group">
                            <label for="exampleInputEmail1">Users File Attach</label>
                            <input type="file" class="form-control" name="user_file[]" multiple>
                          </div>
                     </div>
                 </div>
                  <div class="row">
                     <div class="col-lg-12">
                        <div class="form-group">
                        <label for="exampleInputEmail1">User Email History</label>
                        <textarea class="form-control" placeholder =  "Enter User Email History" name="user_email"></textarea>
                        </div>
                     </div>
                     <div class="col-lg-12">
                          <div class="form-group">
                            <label for="exampleInputEmail1">User Communication History</label>
                             <textarea class="form-control" placeholder =  "Enter User Communication History" name="user_comm"></textarea>
                          </div>
                     </div>
                 </div>
                 <div class="col-lg-12">
                        <label for="exampleInputEmail1">Select Status </label>
                            <select class="form-control" id="new_status" name="now_status">
                                <option value="">Select Status</option>
                                <option value="Open">Open</option>
                                <option value="Close">Close</option>
                            </select>
                        
                     </div>
                     <br>
                      <div class="col-lg-12">
                         <input type="text" class="form-control" id="open_status" name="new_status" multiple>
                     </div>
                   
                  
                </div>
                <!-- /.card-body -->

                <div class="card-footer">
                  <input type="submit" name="newDispute" class="btn btn-primary pull-right">
                </div>
              </form>
            </div>
    <?php
    
}elseif (isset($_POST['newDispute'])) {
    
    extract($_POST);
    $date = date('Y-m-d');
    
 

 echo $query = "INSERT INTO `dispute` VALUES (null,'$email','$dispute_date','$bank','$last_date','$user_email','$user_comm','$new_status','$now_status','Pending','$date')";
    
    die();
    
    $result = mysqli_query($con,$query);
    $last_id = mysqli_insert_id($con);
    
    if($result){


foreach($_FILES['bank_file']['name'] as $i => $name){
        $tmp_name = $_FILES['bank_file']['tmp_name'][$i];
       
        $newFileName = "uploads/".$name;
     if(move_uploaded_file($tmp_name,$newFileName ))
            {
             echo  $query = "INSERT INTO `dispute_files` values(null,'$last_id','$newFileName','bank','$date')";
              $result = mysqli_query($con,$query);
            }else{
             
            }
    
}


foreach($_FILES['user_file']['name'] as $i => $name){
        $tmp_name = $_FILES['user_file']['tmp_name'][$i];
       
        $newFileName = "uploads/".$name;
     if(move_uploaded_file($tmp_name,$newFileName ))
            {
              $query = "INSERT INTO `dispute_files` values(null,'$last_id','$newFileName','user','$date')";
              $result = mysqli_query($con,$query);
             
            }else{
               
            }
    
}

    if($result){
         header("location:index.php");
    }
    }
}elseif (isset($_POST['disputeManage'])) {
    ?>
     <div class="row">
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-info" id="todayLeads">
              <div class="inner">
                 <?php 
                 $today = date("Y-m-d");
                 $query = "SELECT count(*) as today FROM dispute where now_status = 'running'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                ?>
                <h3><?php echo $row['today'];?></h3>
                <p>Total Running Dispute</p>
              </div>
              <div class="icon">
                <i class="ion ion-bag"></i>
              </div>
             
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-success">
              <div class="inner">
                <?php 
                 
                 $today = date("Y-m-d");
                  $query = "SELECT count(*) as total FROM dispute where now_status = 'closed'";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 
                ?>

                <h3><?php echo $row['total'];?></h3>

                <p>Closed Dipute</p>
              </div>
              <div class="icon">
                <i class="ion ion-stats-bars"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-warning">
              <div class="inner">
                 <?php 
                 
                 $today = date("Y-m-d");
                 $query = "SELECT count(*) as total FROM dispute";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 
                ?>
                <h3><?php echo $row['total'];?></h3>

                <p>Total Dispute</p>
              </div>
              <div class="icon">
                <i class="ion ion-person-add"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
     
          <!-- ./col -->
        </div>
    <?php
      $query = "SELECT * FROM dispute where status != 'closed'";
         $result = mysqli_query($con,$query);
    ?>
          <table id="example2" class="table table-bordered table-striped">
                <thead>
                <tr>
                  
                  <th>Email</th>
                  <th>Bank</th>
                  <th>Dispute Date</th>
                  <th>Last Date</th>
                  <th>Current Status</th>
                  <th>Action</th>
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                  <td><?php echo $row['email']?></td>
                  <td><?php echo $row['bank']?></td>
                  <td><?php echo $row['dispute_date']?></td>
                  <td><?php echo $row['last_date']?></td>
                  <td><?php echo $row['status']?></td>
                  <td>
                      <a class="btn btn-info btn-sm view_dispute"  data-value="<?php echo $row['id'];?>">Veiw</a>
                      <!--<a class="btn btn-danger btn-sm" data-value="<?php //echo $row['id'];?>">Delete</a>-->
                  </td>
                </tr>
                <?php } ?>
                 </tbody>              
              </table>
              <script type="text/javascript">
              	 $(function () {
   					
			    $('#example2').DataTable({
			      "paging": true,
			      "lengthChange": true,
			      "searching": true,
			      "ordering": true,
			      "info": true,
			      "autoWidth": true
			    });
			  });
              </script>
    <?php
}elseif (isset($_POST['disputeId'])) {
    $id = $_POST['disputeId'];
    $query = "SELECT * FROM dispute where id = '$id'";
    $result = mysqli_query($con,$query);
    $row2 = mysqli_fetch_assoc($result);
    
    $email = $row2['email'];
    
    $query = "SELECT * FROM new_invoice where pay_to_email = '$email'";
    $result = mysqli_query($con,$query);
    $row = mysqli_fetch_assoc($result);
    ?>
        <div class="card">
        
              <div class="card-body">
                <div class="tab-content">
                  <div class="active tab-pane" id="activity">
                    <!-- Post -->
                    <div class="post">
                      <div class="user-block">
                       
                        <span class="username">
                          <a href="#"><?php echo $row['first']." ". $row['last_name']?></a>
                          <a href="#" class="float-right btn-tool"><i class="fa fa-times"></i></a>
                        </span>
                        <span class="description">Dipute Date - <?php echo $row2['dispute_date']?></span>
                      </div>
                      <!-- /.user-block -->
                    <div class="row">
                     <div class="col-lg-12">
                        <div class="form-group">
                        <label for="exampleInputEmail1">User Email History</label>
                        <textarea class="form-control" placeholder =  "Enter User Email History" name="user_email"><?php echo $row2['user_communication']?></textarea>
                        </div>
                     </div>
                     <div class="col-lg-12">
                          <div class="form-group">
                            <label for="exampleInputEmail1">User Communication History</label>
                             <textarea class="form-control" placeholder =  "Enter User Communication History" name="user_comm"><?php echo $row2['user_communication']?></textarea>
                          </div>
                     </div>
                 </div>
                 <div class="row">
                     <div class="col-lg-6">
                        <div class="form-group">
                        <label for="exampleInputEmail1">Client Status</label>
                       <select class="form-control" id="clientstatus">
                                <option value="">Select Status</option>
                                <option value="Open">Open</option>
                                <option value="Close">Close</option>
                            </select>
                       </div>
                </div>
               <div class="col-lg-6">
                          <div class="form-group">
                            <label for="exampleInputEmail1">Main Status</label>
                             <select class="form-control" id="status" name="last_date">
                                <option value="">Select Status</option>
                                <option value="Open">Pending</option>
                                <option value="Pre-arbitration">Pre-arbitration</option>
                            </select>
                          </div>
                     </div>
                 </div>  
                 <a data-value="<?php echo $row2['id']?>" class="btn btn-info pull-right" value="Update" id="updatedispute">Update</a>
                    </div>
                    <!-- /.post -->

                  <!-- /.tab-pane -->
                </div>
                <!-- /.tab-content -->
              </div><!-- /.card-body -->
            </div>
            
        
            
    <?php
    
}elseif (isset($_POST['updatedisputeId'])) {
    $id = $_POST['updatedisputeId'];
     $client = $_POST['clientstatus'];
     $status = $_POST['status'];
     $query = "update dispute set client_status = '$client', status = '$status' where id = '$id'";

    $result = mysqli_query($con,$query);
   if($result){
       echo "1";
   }
    
}elseif (isset($_POST['addRefund'])) {
    ?>
            <div class="card card-primary">
              <div class="card-header">
                <h3 class="card-title">Add New Refund</h3>
              </div>
              <!-- /.card-header -->
              <!-- form start -->
              <form role="form" action="response.php" method="POST" enctype="multipart/form-data">
                <div class="card-body">
                  <div class="row">
                     <div class="col-lg-6">
                        <div class="form-group">
                        <label for="exampleInputEmail1">Email address</label>
                        <input type="email" class="form-control" name="email" id="userEmailDispute" placeholder="Enter email">
                        </div>
                     </div>
                     <div class="col-lg-6">
                          <div class="form-group">
                            <label for="exampleInputEmail1">Bank</label>
                            <input type="text" class="form-control" name="bank" id="bank" placeholder="Enter Bank ">
                          </div>
                     </div>
                 </div>
                 <div class="col-lg-12">
                          <div class="form-group">
                            <label for="exampleInputEmail1">Bank</label>
                            <input type="text" class="form-control" name="amount" id="amount" placeholder="Enter Refund Amount ">
                          </div>
                     </div>
                 
                  <div class="row">
                     <div class="col-lg-6">
                        <div class="form-group">
                        <label for="exampleInputEmail1">Refund Request Date</label>
                        <input type="date" class="form-control" name="refund_request">
                        </div>
                     </div>
                     <div class="col-lg-6">
                          <div class="form-group">
                            <label for="exampleInputEmail1">Refund  Date</label>
                            <input type="date" class="form-control" name="refund_date">
                          </div>
                     </div>
                 </div>
                  <div class="row">
                     <div class="col-lg-6">
                        <div class="form-group">
                        <label for="exampleInputEmail1">User File Attach</label>
                        <input type="file" class="form-control" name="user_file[]" multiple>
                        </div>
                     </div>
                     <div class="col-lg-6">
                          <div class="form-group">
                            <label for="exampleInputEmail1">Admin File Attach</label>
                            <input type="file" class="form-control" name="admin_file[]" multiple>
                          </div>
                     </div>
                 </div>
                  <div class="row">
                     <div class="col-lg-12">
                        <div class="form-group">
                        <label for="exampleInputEmail1">User Email History</label>
                        <textarea class="form-control" placeholder =  "Enter User Email History" name="user_email"></textarea>
                        </div>
                     </div>
                     <div class="col-lg-12">
                          <div class="form-group">
                            <label for="exampleInputEmail1">User Communication </label>
                             <select class="form-group" name="user_comm">
                                 <option>Yes</option>
                                 <option>No</option>
                             </select>
                          </div>
                     </div>
                 </div>
                 <div class="col-lg-12">
                          <div class="form-group">
                            <label for="exampleInputEmail1">Now Status </label>
                              <select class="form-control" name="now_status">
                                 <option>Refunded</option>
                                 <option>Pending</option>
                             </select>
                          </div>
                     </div>
                  
                </div>
                <!-- /.card-body -->

                <div class="card-footer">
                  <input type="submit" name="newRefund" class="btn btn-primary pull-right">
                </div>
              </form>
            </div>
    <?php
    
}elseif (isset($_POST['newRefund'])) {
    
    extract($_POST);
    $date = date('Y-m-d');
    
 

  $query = "INSERT INTO `refund` VALUES (null,'$email','$bank','$amount','$refund_request','$refund_date','$user_email','$user_comm','$now_status','$now_status','$date')";


    $result = mysqli_query($con,$query);
    $last_id = mysqli_insert_id($con);
    
    if($result){


foreach($_FILES['user_file']['name'] as $i => $name){
        $tmp_name = $_FILES['user_file']['tmp_name'][$i];
       
        $newFileName = "uploads/".$name;
     if(move_uploaded_file($tmp_name,$newFileName ))
            {
             echo  $query = "INSERT INTO `refund_files` values(null,'$last_id','$newFileName','user','$date')";
              $result = mysqli_query($con,$query);
            }else{
             
            }
    
}


foreach($_FILES['admin_file']['name'] as $i => $name){
        $tmp_name = $_FILES['admin_file']['tmp_name'][$i];
       
        $newFileName = "uploads/".$name;
     if(move_uploaded_file($tmp_name,$newFileName ))
            {
              $query = "INSERT INTO `refund_files` values(null,'$last_id','$newFileName','admin','$date')";
              $result = mysqli_query($con,$query);
             
            }else{
               
            }
    
}

    if($result){
        ?>
        <script>alert('Refund Data inserted Successfully..')</script>
        <?php
         header("location:index.php?msg=success");
    }
    }
}elseif (isset($_POST['RefundManage'])) {
    ?>
     <div class="row">
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-info" id="todayLeads">
              <div class="inner">
                 <?php 
                 $today = date("Y-m-d");
                 $query = "SELECT count(*) as today FROM refund";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                ?>
                <h3><?php echo $row['today'];?></h3>
                <p>Total Refund Users</p>
              </div>
              <div class="icon">
                <i class="ion ion-bag"></i>
              </div>
             
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-success">
              <div class="inner">
                <?php 
                 
                 $today = date("Y-m-d");
                  $query = "SELECT sum(refund_amount) as total FROM refund";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 
                ?>

                <h3><?php echo $row['total'];?></h3>

                <p>Refund Total Amount</p>
              </div>
              <div class="icon">
                <i class="ion ion-stats-bars"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-warning">
              <div class="inner">
                 <?php 
                 
                
                 $query = "SELECT sum(refund_amount) as total from refund
                            WHERE MONTH(`created_at`) = MONTH(CURRENT_DATE())";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 
                ?>
                <h3><?php echo $row['total'];?></h3>

                <p>Current Month Refund Amount</p>
              </div>
              <div class="icon">
                <i class="ion ion-person-add"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
          <div class="col-lg-3 col-6">
            <!-- small box -->
            <div class="small-box bg-danger">
              <div class="inner">
                 <?php 
                 
                
                 $query = "SELECT count(*) as total from refund
                            WHERE MONTH(`created_at`) = MONTH(CURRENT_DATE())";
                 $result = mysqli_query($con,$query);
                 $row = mysqli_fetch_assoc($result);
                 
                ?>
                <h3><?php echo $row['total'];?></h3>

                <p>Current Month Refund Users</p>
              </div>
              <div class="icon">
                <i class="ion ion-person-add"></i>
              </div>
            
            </div>
          </div>
          <!-- ./col -->
        </div>
    <?php
      $query = "SELECT * FROM refund";
         $result = mysqli_query($con,$query);
    ?>
          <table id="example2" class="table table-bordered table-striped">
                <thead>
                <tr>
                  
                  <th>Email</th>
                  <th>Bank</th>
                    <th>Amount</th>
                  <th>Request Date</th>
                  <th>Refund Date</th>
                  <th>Current Status</th>
                
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                  <td><?php echo $row['email']?></td>
                  <td><?php echo $row['bank']?></td>
                  <td><?php echo $row['refund_amount']?></td>
                  <td><?php echo $row['refund_request']?></td>
                  <td><?php echo $row['refund_date']?></td>
                  <td><?php echo $row['now_status']?></td>
                 
                </tr>
                <?php } ?>
                 </tbody>              
              </table>
              <script type="text/javascript">
              	 $(function () {
   					
			    $('#example2').DataTable({
			      "paging": true,
			      "lengthChange": true,
			      "searching": true,
			      "ordering": true,
			      "info": true,
			      "autoWidth": true
			    });
			  });
              </script>
    <?php
}elseif(isset($_POST['query'])){
     $name = $_POST['query'];
     
      if(filter_var($name, FILTER_VALIDATE_EMAIL)) {
       $query = "SELECT * FROM new_invoice where pay_to_email like '%$name%' ";
    }
    else {
        $query = "SELECT * FROM new_invoice where first like '%$name%' ";
    }
     
    
     $result = mysqli_query($con,$query);

                ?>
                <div class="table-responsive">
              <table id="example2" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Websitename</th>
                  <th>Email</th>
                  <th>Sign On</th>
                  <th>Country</th>
                  <th>Amount</th>
                  <th>Action</th>
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                  <td class="sorting_1"><?php echo $row['websitename'];?></td>
                  <td><?php echo $row['pay_to_email']?></td>
                  <td><?php echo date('M j Y ', strtotime($row['dates']));?></td>
                  <td><?php echo $row['country']?></td>
                  <td><?php echo $row['amount']?></td>
                  <td>
                      <a class="btn btn-info btn-sm profile"  data-value="<?php echo $row['id'];?>">Veiw</a>
                      <a class="btn btn-danger btn-sm" id="userId" data-value="<?php echo $row['id'];?>">Delete</a>
                  </td>
                </tr>
                <?php } ?>
                 </tbody>              
              </table>
              </div>
              <script type="text/javascript">
              	 $(function () {
   					
			    $('#example2').DataTable({
			      "paging": true,
			      "lengthChange": true,
			      "searching": true,
			      "ordering": true,
			      "order":[[2,"desc"]],
			      "info": true,
			      "autoWidth": true
			    });
			  });
              </script>

              <?php
}elseif($_POST['cus_date2']){
   $cus_date = $_POST['cus_date2'];
  
    ?>
          <div class="position-relative mb-4" >
                  <canvas id="visitors-chart2" height="200"></canvas>
                  
                </div>
         <script> 
         $(document).ready(function(){
          
              $.post("data.php?cus_date=<?php echo $cus_date?>",function (data){
                 
                 
                   var Decline = [];
                    var Success = [];
                    var Days = [];
                    for (var i in data) {
                        Decline.push(data[i].NUM);
                        Success.push(data[i].Success);
                        Days.push(data[i].websitename);
                
                        console.log(name);
                        
                    }  
  //get the line chart canvas
  var ctx = $("#visitors-chart2");

  //line chart data
  var data = {
    labels: Days,
    datasets: [
      {
        label: "Sell",
        data: Success,
        backgroundColor: "Green",
        borderColor: "Green",
        fill: false,
        lineTension: 0,
        radius: 5
      },
      {
        label: "Total Leads",
        data: Decline,
        backgroundColor: "skyBlue",
        borderColor: "blue",
        fill: false,
        lineTension: 0,
        radius: 5
      }
    ]
  };

  //options
  var options = {
    responsive: true,
    title: {
      display: true,
      position: "top",
      text: "Line",
      fontSize: 18,
      fontColor: "#111"
    },
    legend: {
      display: true,
      position: "top",
      labels: {
        fontColor: "#333",
        fontSize: 16
      }
    }
  };

  //create Chart class object
  var chart = new Chart(ctx, {
    type: "bar",
    data: data,
    options: options
  });
  
                })

           })

        
        </script>
    <?php
    
    
}if (isset($_POST['showUpdateUsers'])) {
 $query = "select new_invoice.id,new_invoice.pay_to_email,new_invoice.c_number,new_invoice.country,new_invoice.websitename,user_updates.create_at FROM new_invoice
join user_updates on user_updates.user_id = new_invoice.id
group by pay_to_email";
        $result = mysqli_query($con,$query);

                ?>
                <div class="table-responsive">
              <table id="example2" class="table table-bordered table-striped">
                <thead>
                <tr>
                 <th>Website</th>
                  <th>Email</th>
                  <th>Phone</th>
                  <th>Sign On</th>
                  <th>Country</th>
                  <th>Updates</th>
                  <th>Action</th>
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                  <td class="sorting_1"><?php echo $row['websitename'];?></td>
                  <td><?php echo $row['pay_to_email']?></td>
                  <td><?php echo $row['c_number']?></td>
                  <td><?php echo date('M j Y ', strtotime($row['create_at']));?></td>
                  <td><?php echo $row['country']?></td>
                   <td><?php echo $row['updates']?></td>
                  <td>
                      <a class="btn btn-info btn-sm profileUpdate"  data-value="<?php echo $row['id'];?>">Veiw</a>
                      <a class="btn btn-danger btn-sm" id="userId" data-value="<?php echo $row['id'];?>">Delete</a>
                  </td>
                </tr>
                <?php } ?>
                 </tbody>              
              </table>
              </div>
              <script type="text/javascript">
              	 $(function () {
   					
			    $('#example2').DataTable({
			      "paging": true,
			      "lengthChange": true,
			      "searching": true,
			      "ordering": true,
			      "order":[[3,"desc"]],
			      "info": true,
			      "autoWidth": true
			    });
			  });
              </script>

              <?php
	
}if (isset($_POST['profileUpdate'])) {
    
    $id = $_POST['profileUpdate'];
    
    $query = "select * from new_invoice where id = $id";
    $result = mysqli_query($con,$query);
    $row = mysqli_fetch_assoc($result);
    
    $name = $row['first']."".$row['last_name'] ;
    $websitename = $row['websitename'];
    
    $query = "select * from user_updates where user_id = $id order by id desc";
    $result = mysqli_query($con,$query);
   $i = 0;
                    $array = array();
                    
                    ?>
                    <div class="table-responsive">
                     <table id="example5" class="table table-bordered table-striped">
                <thead>
                <tr>
            
                  <th>Email</th>
                  <th>Firt Name</th>
                  <th>Package</th>
                  <th>Passwords</th>
                  
                  <th>Website</th>
                   <th>Days</th>
                  <th>Short Name</th>
                  <th>Amount</th>
                  <th>Last Name</th>
                  <th>Phone</th>
                   <th>Address</th>
                  <th>City</th>
                  <th>Country</th>
                   <th>Zip Code</th>
                  <th>State</th>
                </tr>
                </thead>
                <tbody>
                   
                    
                    <?php
             while($row = mysqli_fetch_assoc($result)){
        
             $array1 =json_decode($row['new_update'],true);
  
            $array2 = json_decode($row['old_update'],true);
          
            ?>
          
            
                    <tr style="background-color:#93CCEE">
                  <td><?php echo $array2[2]?></td>
                  <td><?php echo $array2[4]?></td>
                  <td><?php echo $array2[5]?></td>
                  <td><?php echo $array2[7]?></td>
                  <td><?php echo $array2[9]?></td>
                  <td><?php echo $array2[12]?></td>
                  <td><?php echo $array2[13]?></td>
                  <td><?php echo $array2[14]?></td>
                  <td><?php echo $array2[16]?></td>
                  <td><?php echo $array2[17]?></td>
                  <td><?php echo $array2[18]?></td>
                  <td><?php echo $array2[19]?></td>
                  <td><?php echo $array2[20]?></td>
                  <td><?php echo $array2[21]?></td>
                   <td><?php echo $array2[22]?></td>
                    </tr>           
                <tr role="row" class="odd">
                  <td><?php echo $array1[2]?></td>
                  <td><?php echo $array1[4]?></td>
                  <td><?php echo $array1[5]?></td>
                  <td><?php echo $array1[7]?></td>
                   <td><?php echo $array1[8]?></td>
                  <td><?php echo $array1[12]?></td>
                  <td><?php echo $array1[13]?></td>
                  <td><?php echo $array1[14]?></td>
                   <td><?php echo $array1[16]?></td>
                  <td><?php echo $array1[17]?></td>
                  <td><?php echo $array1[18]?></td>
                  <td><?php echo $array1[19]?></td>
                  <td><?php echo $array1[20]?></td>
                  <td><?php echo $array1[21]?></td>
                   <td><?php echo $array1[22]?></td>
                </tr>
                <?php
                  $diff = array_diff($array2, $array1);
             $array[$i++][] = $diff;
                } ?>
               

              </tbody>              
              </table>
            </div>
            
              <script type="text/javascript">
              	$(document).ready(function() {
				    $('#example5').DataTable( {
				        paging: true,
					   pageLength: 10,
					   "order":[[3,"desc"]],
				    });
				});
              </script>
            <?php
    

           
             
             $arr=[];
array_walk_recursive($array, function($k){global $arr; $arr[]=$k;});

            
    ?>
  
<?php
}elseif(isset($_POST['todayRenew'])){
$date = date("Y-m-d");
   $query = "SELECT new_invoice.* from user_status 
                            join new_invoice on new_invoice.id = user_status.user_id
                            WHERE user_status.status = 'Success'
                            AND new_invoice.websitename = 'http://member.tvcnw.com'
                            AND user_status.created_at = '$date'
                            order by id desc";
         $result = mysqli_query($con,$query);

                ?>
                <a href="javascript:void(0)" class="btn btn-info pull-right" id="addGroup"> Add Group</a><br /><br />
              <table id="example2" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Email</th>
                  <th>Phone</th>
                  <th>Country</th>
                  <th>Created_at</th>
                 
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                  <td class="sorting_1"><?php echo $row['pay_to_email'];?></td>
                  <td><?php echo $row['c_number']?></td>
                  <td><?php echo $row['country']?></td>
                  <td> <?php echo date('M j Y ', strtotime($row['dates']))?></a></td>
                </tr>
                <?php } ?>
                 </tbody>              
              </table>
              <script type="text/javascript">
                 $(function () {
            
          $('#example2').DataTable({
            "paging": true,
            "lengthChange": true,
            "searching": true,
            "ordering": true,
            "order":[[3,"desc"]],
            "info": true,
            "autoWidth": true
          });
        });
              </script>

              <?php
}elseif(isset($_POST['todaysellRenew'])){

   $query = "SELECT new_invoice.* from user_status 
                            join new_invoice on new_invoice.id = user_status.user_id
                            WHERE user_status.status = 'Success'
                            AND new_invoice.websitename = 'http://member.tvcnw.com'
                            order by new_invoice.id desc";
         $result = mysqli_query($con,$query);

                ?>
                <a href="javascript:void(0)" class="btn btn-info pull-right" id="addGroup"> Add Group</a><br /><br />
              <table id="example2" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Email</th>
                  <th>Phone</th>
                  <th>Country</th>
                  <th>Created_at</th>
                 
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                  <td class="sorting_1"><?php echo $row['pay_to_email'];?></td>
                  <td><?php echo $row['c_number']?></td>
                  <td><?php echo $row['country']?></td>
                  <td> <?php echo date('M j Y ', strtotime($row['dates']))?></a></td>
                </tr>
                <?php } ?>
                 </tbody>              
              </table>
              <script type="text/javascript">
                 $(function () {
            
          $('#example2').DataTable({
            "paging": true,
            "lengthChange": true,
            "searching": true,
            "ordering": true,
            "order":[[3,"desc"]],
            "info": true,
            "autoWidth": true
          });
        });
              </script>

              <?php
}elseif(isset($_POST['requestRenew'])){

   $query = "SELECT *  from new_invoice
            where websitename = 'http://member.tvcnw.com'
            order by id desc";
         $result = mysqli_query($con,$query);

                ?>
                <a href="javascript:void(0)" class="btn btn-info pull-right" id="addGroup"> Add Group</a><br /><br />
              <table id="example2" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Email</th>
                  <th>Phone</th>
                  <th>Country</th>
                  <th>Created_at</th>
                 
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                  <td class="sorting_1"><?php echo $row['pay_to_email'];?></td>
                  <td><?php echo $row['c_number']?></td>
                  <td><?php echo $row['country']?></td>
                  <td> <?php echo date('M j Y ', strtotime($row['dates']))?></a></td>
                </tr>
                <?php } ?>
                 </tbody>              
              </table>
              <script type="text/javascript">
                 $(function () {
            
          $('#example2').DataTable({
            "paging": true,
            "lengthChange": true,
            "searching": true,
            "ordering": true,
            "order":[[3,"desc"]],
            "info": true,
            "autoWidth": true
          });
        });
              </script>

              <?php
}elseif(isset($_POST['totalRenew'])){

   $query = "SELECT new_invoice.* from user_status 
                            join new_invoice on new_invoice.id = user_status.user_id
                            WHERE user_status.status = 'Success'
                            AND new_invoice.websitename = 'http://member.tvcnw.com'
                            order by  new_invoice.id desc";
         $result = mysqli_query($con,$query);

                ?>
                <a href="javascript:void(0)" class="btn btn-info pull-right" id="addGroup"> Add Group</a><br /><br />
              <table id="example2" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Email</th>
                  <th>Phone</th>
                  <th>Country</th>
                  <th>Created_at</th>
                 
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                  <td class="sorting_1"><?php echo $row['pay_to_email'];?></td>
                  <td><?php echo $row['c_number']?></td>
                  <td><?php echo $row['country']?></td>
                  <td> <?php echo date('M j Y ', strtotime($row['dates']))?></a></td>
                </tr>
                <?php } ?>
                 </tbody>              
              </table>
              <script type="text/javascript">
                 $(function () {
            
          $('#example2').DataTable({
            "paging": true,
            "lengthChange": true,
            "searching": true,
            "ordering": true,
            "order":[[3,"desc"]],
            "info": true,
            "autoWidth": true
          });
        });
              </script>

              <?php
}elseif(isset($_POST['check'])){
    $query ="SELECT * FROM notification WHERE create_at >= DATE_SUB(CURDATE(), INTERVAL 1 HOUR) and veiw = 0 ";
    $result = mysqli_query($con,$query);
    $num = mysqli_num_rows($result);
    
    while($row = mysqli_fetch_assoc($result)){
        $domain = $row['user_id'];
        $status = $row['message'];
    }
    
    $query = "select * from new_invoice where id = '$domain'";
    $result= mysqli_query($con,$query);
    $row  = mysqli_fetch_assoc($result);
    $num = mysqli_num_rows($result);
    if($num > 0){
        echo $row['websitename']." (".$row['country']." ".$status.")";
    }else{
        echo "working";
    }
}elseif (isset($_POST['addtemplate'])) {
    ?>
            <div class="card card-primary">
              <div class="card-header">
                <h3 class="card-title">Add New Email Template</h3>
              </div>
              <!-- /.card-header -->
              <!-- form start -->
              <form role="form" action="response.php" method="POST" enctype="multipart/form-data">
                <div class="card-body">
                  <div class="row">
                 
                 
                     <div class="col-lg-12">
                        <div class="form-group">
                        <label for="exampleInputEmail1">User Email History</label>
                       <textarea class="ckeditor" name="emailText" style="width: 100%; height: 200px; font-size: 14px; line-height: 18px; border: 1px solid rgb(221, 221, 221); padding: 10px;" placeholder="Place some text here"></textarea>

                        </div>
                     </div>
                  
                </div>
                <!-- /.card-body -->

                <div class="card-footer">
                  <input type="submit" name="templateAdd" class="btn btn-primary pull-right">
                </div>
              </form>
            </div>
            
              
<script src="ck/ckeditor.js"></script>
    <?php
    
}elseif($_POST['templateAdd']){
    $date = date('Y-m-d H:i:s A');
    $msg = addslashes($_POST['emailText']);
    
   $query ="INSERT INTO ecline_template  VALUES (null,'$msg',0,'$date')";
    $result = mysqli_query($con,$query);
    if($result){
        echo "success";
    }
    
}elseif(isset($_POST['managetemplate'])){

   $query = "SELECT * from decline_template";
         $result = mysqli_query($con,$query);

                ?>
                <a href="javascript:void(0)" class="btn btn-info pull-right" id="addGroup"> Add Group</a><br /><br />
              <table id="example2" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Template</th>
                  <th>Status</th>
                  <th>Date</th>
                  <th>Action</th>
                 
                </tr>
                </thead>
                <tbody>
                  <?php
                      while($row = mysqli_fetch_assoc($result)){
              
                  ?>              
                <tr role="row" class="odd">
                  <td class="sorting_1"><?php echo substr($row['template'],0,50);?></td>
                  <td><?php echo $row['status']?></td>
                 
                  <td> <?php echo date('M j Y ', strtotime($row['dates']))?></a></td>
                   <td><a>update</a></td>
                </tr>
                <?php } ?>
                 </tbody>              
              </table>
              <script type="text/javascript">
                 $(function () {
            
          $('#example2').DataTable({
            "paging": true,
            "lengthChange": true,
            "searching": true,
            "ordering": true,
            "order":[[3,"desc"]],
            "info": true,
            "autoWidth": true
          });
        });
              </script>

              <?php
}elseif(isset($_GET['customMonth'])){
  $month = $_GET['customMonth'];
  $year = explode("-",$_GET['year']);
  $month_number = date("n",strtotime($month));
  $d= cal_days_in_month(CAL_GREGORIAN,$month_number,$year[0]);
  if(strlen($month_number) == 1){
    $month_number = "0".$month_number;
  }
  $start = $year[0]."-".$month_number."-01";
  $end = $year[0]."-".$month_number."-".$d;
  
  ?>
    <table id="example1" class="table table-bordered table-striped dataTable" role="grid" aria-describedby="example1_info">
      <thead>
        <th>Domain</th>
        <th>Total Leads</th>
        <th>Total Sell(expected)</th>
        <th>Total Decline</th>
        <th>Decline Amount</th>
        <th>Success Leads</th>
        <th>Success Amount</th>
        
      </thead>
      <tbody>
  <?php

    $query1 = "SELECT new_invoice.websitename as name, SUM( new_invoice.amount ) AS Sell_total, COUNT( new_invoice.id ) AS count_total from user_status
    JOIN new_invoice ON new_invoice.id = user_status.user_id
    WHERE new_invoice.dates >= '$start'
    AND new_invoice.dates <= '$end'
    and user_status.status = 'Decline'
    GROUP BY new_invoice.websitename";
  $result1 = mysqli_query($con,$query1);
  $dec_sell = array();
  $dec_total = array();
        while($row = mysqli_fetch_assoc($result1)){
          $name = $row['name'];
        $dec_sell[$name] = $row['Sell_total'];
        $dec_total[$name] = $row['count_total'];
       }
       

 $query2 = "SELECT new_invoice.websitename as name, SUM( new_invoice.amount ) AS Sell_total, COUNT( new_invoice.id ) AS count_total from user_status
    JOIN new_invoice ON new_invoice.id = user_status.user_id
    WHERE new_invoice.dates >= '$start'
    AND new_invoice.dates <= '$end'
    and user_status.status = 'Success'
    GROUP BY new_invoice.websitename";
  $result2 = mysqli_query($con,$query2);
  $suc_sell = array();
  $suc_total = array();
        while($row = mysqli_fetch_assoc($result2)){
          $name = $row['name'];
        $suc_sell[$name] = $row['Sell_total'];
        $suc_total[$name] = $row['count_total'];
       }
 $query3 = "SELECT new_invoice.websitename as name, SUM( new_invoice.amount ) AS Sell_total, COUNT( new_invoice.id ) AS count_total from user_status
    JOIN new_invoice ON new_invoice.id = user_status.user_id
    WHERE new_invoice.dates >= '$start'
    AND new_invoice.dates <= '$end'
    GROUP BY new_invoice.websitename";
  $result3 = mysqli_query($con,$query3);

        $i = 0;
        while($row = mysqli_fetch_assoc($result3)){
          $name = $row['name'];
       
    ?>
                <tr role="row" class="odd">
                  <td class="sorting_1 month" style="cursor: pointer;"><?php echo $row['name']?></td>
                  <td><?php echo $row['count_total']?></td>
                  <td>$<?php echo $row['Sell_total']?></td>
                  <td><?php
                  if($dec_total[$name] == ''){
                   echo 0;
                 }else{
                   echo $dec_total[$name];
                 }
                   ?></td>

                  <td>$<?php 
                     if($dec_sell[$name] == ''){
                   echo 0;
                 }else{
                   echo $dec_sell[$name];
                 }
                  ?></td>
                  <td><?php
                  if($suc_total[$name] == ''){
                   echo 0;
                 }else{
                   echo $suc_total[$name];
                 }
                   ?></td>

                  <td>$<?php 
                     if($suc_sell[$name] == ''){
                   echo 0;
                 }else{
                   echo $suc_sell[$name];
                 }
                  ?></td>   
                </tr>

        <?php
        $i++;
          }
        ?>
            </tbody>
              </table>
              <?php
}elseif (isset($_POST['pay_link'])) {
  extract($_POST);
 $query = "INSERT INTO `order_link`(`email`, `price`, `website`) VALUES ('$email','$amount','$websitename')";
  $result = mysqli_query($con,$query);
 
  if($result){
   header("location:create_order.php?insert=success");
  }else{
    header("location:create_order.php?insert=error");
  }
}elseif(isset($_GET['order_linkStatus'])){
  $status = $_GET['order_linkStatus'];
  $id     = $_GET['linkorder_id'];
  $query = "UPDATE `order_link` SET `status`='$status' WHERE id = '$id'";
  $result = mysqli_query($con,$query);
 
  if($result){
    echo "1";
  }
}elseif(isset($_GET['order_leadDl'])){

  $id     = $_GET['order_leadDl'];
  $query = "DELETE FROM `order_link` WHERE id = '$id'";
  $result = mysqli_query($con,$query);
 
  if($result){
    header("location:order_link.php?message=success");
  }
}elseif(isset($_POST['Addadminuser'])){
  extract($_POST);

 $query ="INSERT INTO `adminuser`(`email`, `password`, `status`) VALUES ('$email','$password','$status')";
  $result = mysqli_query($con,$query);
 
  if($result){
    header("location:users.php?message=success");
  }
}elseif (isset($_GET['userMenu'])) {
    $id = $_GET['userMenu'];
    
            $query = "select * from domains";
            $result = mysqli_query($con,$query);
            $i = 1;
            ?>
            <input type="hidden" name="user_id" value="<?php echo $id?>">
            <?php
            while($row = mysqli_fetch_assoc($result)){
                $menu_id = $row['id'];
                $q = "select * from menu_asigned where user_id = '$id' and menu_id ='$menu_id'";
                $r = mysqli_query($con,$q);
                $r_num = mysqli_num_rows($r);
                if($r_num > 0){
                    ?>
                   
        <div class="form-group col-md-4">
          <div class="checkbox checkbox-success">
            <input id="checkbox<?php echo $i;?>" value="<?php echo $row['id']?>" name="menu<?php echo $i;?>" type="checkbox" checked>
           
            <label for="checkbox<?php echo $i;?>">
                <?php echo $row['website']?>
            </label>
          </div>
        </div>
        <?php
                }else{
        ?>
        <div class="form-group col-md-4">
          <div class="checkbox checkbox-success">
            <input id="checkbox<?php echo $i;?>" value="<?php echo $row['id']?>" name="menu<?php echo $i;?>" type="checkbox">
            <label for="checkbox<?php echo $i;?>">
                <?php echo $row['website']?>
                 
            </label>
          </div>
        </div>
       <?php
    }
       $i++;
       }
       
}elseif (isset($_POST['menusAdd'])) {
    extract($_POST);

 print_r($_POST);
 
  $q = "DELETE FROM `menu_asigned` WHERE user_id = '$user_id'";
   $r = mysqli_query($con,$q);
    foreach ($_POST as $key => $value) {
      
        if($key == "user_id" || $key =="menusAdd"){
            
        }else{
         echo $q = "INSERT INTO `menu_asigned`(`user_id`, `menu_id`) VALUES ('$user_id','$value')";
               $r = mysqli_query($con,$q);
                
        }
       
    }
 
    header("location:users.php");

}

?>
