<? 
include_once("valida_sessao.php");
protegePagina(); 
include_once("adm_head.php");
?>

<script type="text/javascript" src="js/busca.js"></script>
<script type="text/javascript" src="js/jquery-1.5.1.min.js"></script>

<span class="dir">Relatórios</span>
</div>

<div id="conteudo">


<?php

$mes = date("m");
$ano = date("Y");

if (isset($_POST['submit'])) { 

$rel = $_POST['rel'];
$mes = $_POST['mes'];
$ano = $_POST['ano'];

header("Location: ".$rel.".php?mes=".$mes."&ano=".$ano);
	
}
?>

<script type="text/javascript">
var z = 0;
$(document).ready(function(){ 
 	
 	$("#relatorio").load("bnr_rel.php?mes=<?=$mes;?>&ano=<?=$ano;?>");
  	
   $("#relmes").click(function(){
	   
	var a = $("#mes").val();
	var b = $("#ano").val();  
	var c = $("#rel").val();
	z = 0;
	
   $("#relatorio").load(c+".php?mes="+a+"&ano="+b);
 
   });
   
   
   $("#relano").click(function(){	   
	 
	var b = $("#ano").val();
	var c = $("#rel").val();
	z = 1;
	
   $("#relatorio").load(c+"_total.php?ano="+b);
 
   });
   
   $("#rel").change(function () {
	   
	    var d = $("#rel").val();
	   
	   $("#relatorio").load(d+".php?mes=<? echo $mes ?>&ano=<? echo $ano ?>");

	});
	

});

//inicio paginação ajax
function prev(pg,total){
	
		var a = $("#mes").val();
		var b = $("#ano").val();  
		var c = $("#rel").val();
	   
	   if(total == 0){
	   $("#relatorio").load(c+".php?mes="+a+"&ano="+b+"&pg="+pg);
	   }else{
		$("#relatorio").load(c+"_total.php?mes="+a+"&ano="+b+"&pg="+pg);
	   }
}

function pag(pg,total){
		
		var a = $("#mes").val();
		var b = $("#ano").val();  
		var c = $("#rel").val();
	   
	   if(total == 0){
	   $("#relatorio").load(c+".php?mes="+a+"&ano="+b+"&pg="+pg);
	   }else{
		$("#relatorio").load(c+"_total.php?mes="+a+"&ano="+b+"&pg="+pg);
	   }
}


function next(pg,total){
		
		var a = $("#mes").val();
		var b = $("#ano").val();  
		var c = $("#rel").val();
	   
	   if(total == 0){
	   $("#relatorio").load(c+".php?mes="+a+"&ano="+b+"&pg="+pg);
	   }else{
		$("#relatorio").load(c+"_total.php?mes="+a+"&ano="+b+"&pg="+pg);
	   }
}
//fim paginação ajax

//busca ajax
function recuperardados() {
	var busca = $("#busca").val();
	var ajax = new AJAX();

		var a = $("#mes").val();
		var b = $("#ano").val();  
		var c = $("#rel").val();

	if(z==0){		
		ajax.Updater(c+".php?mes="+a+"&ano="+b+"&digito="+busca,"relatorio","get","<br /><br /><center><img src=imagem/loading.png></center>");
	}else{
		ajax.Updater(c+"_total.php?mes="+a+"&ano="+b+"&digito="+busca,"relatorio","get","<br /><br /><center><img src=imagem/loading.png></center>");
	}
} 
</script>




<form method="POST" action="<?=$_SERVER['PHP_SELF']?>" name="rel">

<table align="center">
<tr>
		<td><img src="imagem/importante.gif" />
        Tipo de Relatório<br />
        <select name="rel" id="rel">        
        <option value="bnr_rel">Banners</option>        
        </select>        
        </td>
        <td><img src="imagem/importante.gif" />
        Mês <br />
        <select name="mes" id="mes">        
        <option value="01" <? if($mes == 01){ echo "selected";} ?> >Janeiro</option>
        <option value="02" <? if($mes == 02){ echo "selected";} ?> >Fevereiro</option>
        <option value="03" <? if($mes == 03){ echo "selected";} ?> >Março</option>
        <option value="04" <? if($mes == 04){ echo "selected";} ?> >Abril</option>
        <option value="05" <? if($mes == 05){ echo "selected";} ?> >Maio</option>
        <option value="06" <? if($mes == 06){ echo "selected";} ?> >Junho</option>
        <option value="07" <? if($mes == 07){ echo "selected";} ?> >Julho</option>
        <option value="08" <? if($mes == 08){ echo "selected";} ?> >Agosto</option>
        <option value="09" <? if($mes == 09){ echo "selected";} ?> >Setembro</option>
        <option value="10" <? if($mes == 10){ echo "selected";} ?> >Outubro</option>
        <option value="11" <? if($mes == 11){ echo "selected";} ?> >Novembro</option>
        <option value="12" <? if($mes == 12){ echo "selected";} ?> >Dezembro</option>
        </select> 
        </td> 
        <td><img src="imagem/importante.gif" />
        Ano <br />
        <input type="text" id="ano" name="ano" value="<? echo $ano ?>" />
        </td>  
        <td><br />       
        <input type="button" id="relmes" name="relmes" value="Relatório do Mês" />
        </td>
        <td><br />       
        <input type="button" id="relano" name="relano" value="Relatório do Ano" />
        </td>       
</tr>
</table>
</form>


<form name="form" action="" onSubmit="return false">
Busca:<br />
<input id="busca" name="busca" value="" onKeyUp="recuperardados()" />
</form> 



<div id="relatorio"></div>
</div>



<? include_once("adm_foot.php"); ?>