<?php
$id=$_GET['id'];

include("database_connection.php");

  function cleanData($str)
  {
    $str = preg_replace("/\t/", "\\t", $str);
    $str = preg_replace("/\r?\n/", "\\n", $str);
    if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
  }

  // filename for download
  $filename = "Caller Report From" .$id.  ".xls";

 	header("Content-Disposition: attachment; filename=\"$filename\"");
  	header("Content-Type: application/vnd.ms-excel");

  $flag = false;
 ?><table border="1">
	<tr> 
		<th>Caller Name</th>
		<th>Total</th>
		</tr>
	<?php
	$dump_date=$id;
	$queryr="SELECT distinct(caller_name) FROM `liccalliing_tbl` WHERE calling_date='$dump_date' union SELECT distinct(caller_name) FROM `tvr_tbl` WHERE calling_date='$dump_date' ";
 
	$resultr = MYSQLI_QUERY($conn,$queryr);
		
	 $j=1;
	while($data=mysqli_fetch_array($resultr)) {	
	$caller_name=$data['caller_name'];
	
	$sqltotal="select count(id) as num from tvr_tbl where caller_name='$caller_name' and  calling_date='$dump_date' " ;
	$resulttotal=mysqli_query($conn,$sqltotal);
	$datatotal=mysqli_fetch_array($resulttotal);
	$total1=$datatotal[0];
	$sqltotalsbi2="select count(id) as num from liccalliing_tbl where caller_name='$caller_name'  and  calling_date='$dump_date' " ;
	$resulttotalsbi2=mysqli_query($conn,$sqltotalsbi2);
	$datatotalsbi2=mysqli_fetch_array($resulttotalsbi2);
	$totalsbi2=$datatotalsbi2[0];
	$totaltvr +=$total1;
	$totallic +=$totalsbi2;

	$total=$total1;
	
		
	
	?>

<tr  height="15">
<td align="center"><font size="2"><b><?php echo strtoupper($data['caller_name']);?></b></font></td>
<td   align="center"><font size="2"><b><?php echo $total+$totalsbi2;?></b></font></td>

</tr>
<?php
	$j++; }
	?>
<tr >
<td align="center"><font size="4"><b>Total</b></font></td>
<td  align="center" ><font size="4"><b><?php echo $totaltvr+$totallic;?></b></font></td>
</tr>


</table>

