<?
session_start();
require("../conectar.php");
require("funciones.php");
$fi=$_GET['fi'];
$ff=$_GET['ff'];
$medio=$_GET['medio'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<!--[if lt IE 7 ]> <html class="ie ie6 no-js" lang="en"> <![endif]-->
<!--[if IE 7 ]>    <html class="ie ie7 no-js" lang="en"> <![endif]-->
<!--[if IE 8 ]>    <html class="ie ie8 no-js" lang="en"> <![endif]-->
<!--[if IE 9 ]>    <html class="ie ie9 no-js" lang="en"> <![endif]-->
<!--[if gt IE 9]><!--><html class="no-js" lang="en"><!--<![endif]-->
<html>
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
		<title>Resultados de periodo Mexico en renta</title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
		<link rel="shortcut icon" href="../favicon.ico"> 

		<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
		<script type="text/javascript" src="js/highcharts.js"></script>
		<script type="text/javascript" src="js/themes/grid.js"></script>
		<script type="text/javascript" src="js/modules/exporting.js"></script>
</head>		
<body>
<center>
<table class="ocupacion" border="1">
  <tr>
    <th>No</th>
    <th>Medio </th>
    <th>Submedio </th>
	<th>Total</th>
	<th>%</th>
  </tr>
  <?
   $totalclientes=0;$x=0;
   $sql="select id from medio where canal='$medio'";
   $ejecuta=mysql_query($sql);
   $reg=mysql_fetch_array($ejecuta);
   $med=$reg['id'];

	$ren.="'0'";  
	$sql="SELECT count(r.submedio) as cuantos,r.submedio as sub from renta as r
	where r.fecha between '$fi' and '$ff' and r.medio='$med' GROUP BY sub";  
	$query=mysql_query($sql);
	$i=1;
	while($mediop=mysql_fetch_array($query))
		{
		$totalclientespor=$totalclientespor + $mediop['cuantos'];
		}
	$query=mysql_query($sql);
	while($medios=mysql_fetch_array($query))
		{
		  //if($med==1){
		    $dir="select distinct(descripcion) as des from directorios where id='$medios[sub]'";
			$ejedir=mysql_query($dir);
			$nom=mysql_fetch_array($ejedir);
			$totalclientes=$totalclientes + $medios['cuantos'];
			$porc=($medios['cuantos']/$totalclientespor)*100;
			$totpor=$totpor + $porc;
	?>
	  <tr>
	    <td><?echo $i;?></td><td><?echo $medio;?></td><td><?echo $nom['des'];?></td><td align="center"><?echo $medios['cuantos'];?></td><td><?echo porcentaje($porc);?></td>
	  </tr>
	<?
			//echo $nom['des']."-".$nom['con'].$medios['cuantos']."<br>";
		  //}
		
		$i++;
		}      
 ?>
    <tr><td colspan="3" align="right"><b>Total:</b></td><td align="center"><b><?echo $totalclientes;?></b></td><td><b><?echo porcentaje($totpor);?></b></td></tr>
		</table>
		</center>
</body>