<?php
include("conexao.php");
include_once("functions.php");
include_once(Idioma(1));
if(ProtegePag() == true){
global $_TRA;

$ColunaAcesso = array('OpcoesRelatorio');
$VerificarAcesso = VerificarAcesso('opcoes', $ColunaAcesso);
$OpcoesRelatorio = $VerificarAcesso[0];

if($OpcoesRelatorio == 'S'){

$caduser = empty($_POST['caduser']) ? '' : $_POST['caduser'];
$rev = empty($_POST['rev']) ? '' : $_POST['rev'];
$perfil = empty($_POST['perfil']) ? '' : $_POST['perfil'];
$tipo = empty($_POST['tipo']) ? '' : $_POST['tipo'];

if(empty($caduser)){
	echo MensagemAlerta($_TRA['erro'], $_TRA['sur'], "danger");
}
elseif(empty($rev)){
	echo MensagemAlerta($_TRA['erro'], $_TRA['edr'], "danger");
}
elseif(empty($perfil)){
	echo MensagemAlerta($_TRA['erro'], $_TRA['sup'], "danger");
}
elseif(empty($tipo)){
	echo MensagemAlerta($_TRA['erro'], $_TRA['teuco'], "danger");
}
else{
				
	$GerarRelatorio = GerarRelatorio($caduser, $rev, $perfil, $tipo);
?>

							<div class="btn-group pull-right" style="padding:0px 0px 15px 0px;">
                                        <button class="btn btn-danger dropdown-toggle" data-toggle="dropdown"><i class="fa fa-bars"></i> <?php echo $_TRA['et']; ?></button>
                                        <ul class="dropdown-menu">
                                            <li><a href="#" onClick ="SalvarPDF();"><img src='img/icons/pdf.png' width="24"/> <?php echo $_TRA['pdf']; ?></a></li>
                                            <li><a href="#" onClick ="SalvarDOC();"><img src='img/icons/word.png' width="24"/> <?php echo $_TRA['word']; ?></a></li>
                                            <li><a href="#" onClick ="SalvarExcel();"><img src='img/icons/xls.png' width="24"/> <?php echo $_TRA['excel']; ?></a></li>
                                            <li><a href="#" onClick ="SalvarPNG();"><img src='img/icons/png.png' width="24"/> <?php echo $_TRA['png']; ?></a></li>
                                            
                                        </ul>
                            </div>


						<?php
						$VerificarTipoSAT = VerificarTipo('SAT');
						if( ($tipo == "SAT") && ($VerificarTipoSAT > 0) || ($tipo == "T") && ($VerificarTipoSAT > 0) ){
						?>
						<div class="panel panel-default">
                                <div class="panel-heading">
                                   <h3 class="panel-title"><?php echo $_TRA['satelite']; ?></h3>                                  
                                </div>
                                
                                <div class="panel-body">
                                    <div class="table-responsive">
                                     
                                     
                                       <table id="Tabela" class="SalvarTabela table table-striped">
                               <thead>
                               		<tr>
                                    	<th><?php echo $_TRA['Perfil']; ?></th>
                                    	<th><?php echo $_TRA['nome']; ?></th>
                                        <th><?php echo $_TRA['Usuario']; ?></th>
                                        <th><?php echo $_TRA['vpu']; ?></th>
                                        <th><?php echo $_TRA['Ativos']; ?></th>
                                        <th><?php echo $_TRA['apc']; ?></th>
                                        <th><?php echo $_TRA['vac']; ?></th>
                                        <th><?php echo $_TRA['vacc']; ?></th>
                                    </tr>
                                </thead>
                                <tbody>
                                        <?php
									
									for($i=0; $i<count($GerarRelatorio); $i++){
									
									if($GerarRelatorio[$i][0] == "T"){
										$perfil = $_TRA['Todos'];
									}
									else{
										$perfil = SelecionarNomePerfil($GerarRelatorio[$i][0]);
									}
									
									echo "	
                                        <tr>
											<td width=\"50\">".$perfil."</td>
											<td>".$GerarRelatorio[$i][1]."</td>
											<td>".$GerarRelatorio[$i][2]."</td>
											<td>".$GerarRelatorio[$i][3]."</td>
											<td>".$GerarRelatorio[$i][4]."</td>
											<td>".$GerarRelatorio[$i][5]."</td>
											<td>".$GerarRelatorio[$i][6]."</td>
											<td>".$GerarRelatorio[$i][7]."</td>
                                       	 ";
									
								 	echo "</tr>";
									}
								  
										?>
										
                                            </tbody>
                                        </table>
                                                                 
                                    </div>
                                </div>
                            </div>
                            
                            <?php
							}
							
							$VerificarTipoCAB = VerificarTipo('CAB');
							if( ($tipo == "CAB") && ($VerificarTipoCAB > 0) || ($tipo == "T") && ($VerificarTipoCAB > 0) ){
							?>
                            
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                   <h3 class="panel-title"><?php echo $_TRA['cabo']; ?></h3>                                  
                                </div>
                                
                                <div class="panel-body">
                                    <div class="table-responsive">
                                     
                                     
                                       <table id="Tabela" class="SalvarTabela table table-striped">
                               <thead>
                               		<tr>
                                    	<th><?php echo $_TRA['Perfil']; ?></th>
                                    	<th><?php echo $_TRA['nome']; ?></th>
                                        <th><?php echo $_TRA['Usuario']; ?></th>
                                        <th><?php echo $_TRA['vpu']; ?></th>
                                        <th><?php echo $_TRA['Ativos']; ?></th>
                                        <th><?php echo $_TRA['apc']; ?></th>
                                        <th><?php echo $_TRA['vac']; ?></th>
                                        <th><?php echo $_TRA['vacc']; ?></th>
                                    </tr>
                                </thead>
                                <tbody>
                                        <?php
									
									for($i=0; $i<count($GerarRelatorio); $i++){
									
									if($GerarRelatorio[$i][0] == "T"){
										$perfil = $_TRA['Todos'];
									}
									else{
										$perfil = SelecionarNomePerfil($GerarRelatorio[$i][0]);
									}
									
									echo "	
                                        <tr>
											<td width=\"50\">".$perfil."</td>
											<td>".$GerarRelatorio[$i][1]."</td>
											<td>".$GerarRelatorio[$i][2]."</td>
											<td>".$GerarRelatorio[$i][8]."</td>
											<td>".$GerarRelatorio[$i][9]."</td>
											<td>".$GerarRelatorio[$i][10]."</td>
											<td>".$GerarRelatorio[$i][11]."</td>
											<td>".$GerarRelatorio[$i][12]."</td>
                                       	 ";
									
								 	echo "</tr>";
									}
								  
										?>
										
                                            </tbody>
                                        </table>
                                                                 
                                    </div>
                                </div>
                            </div>
                            
                            <?php
							}
							?>
                            
        <!-- START THIS PAGE PLUGINS-->        
        <script type='text/javascript' src='js/plugins/icheck/icheck.min.js'></script>
        <script type="text/javascript" src="js/plugins/mcustomscrollbar/jquery.mCustomScrollbar.min.js"></script>
                                    
        <script type="text/javascript" src="js/plugins/tableexport/libs/FileSaver/FileSaver.min.js"></script>
        <script type="text/javascript" src="js/plugins/tableexport/libs/jsPDF/jspdf.min.js"></script>
        <script type="text/javascript" src="js/plugins/tableexport/libs/jsPDF-AutoTable/jspdf.plugin.autotable.js"></script>
        <script type="text/javascript" src="js/plugins/tableexport/libs/html2canvas/html2canvas.min.js"></script>
        <script type="text/javascript" src="js/plugins/tableexport/tableExport.min.js"></script>
        <script type="text/javascript" src="js/plugins/tableexport/tableExport.js"></script>
        
        <script type="text/javascript" src="js/plugins.js"></script>
        
        <script type="text/javascript">
        function SalvarPDF(){
			
					$('.SalvarTabela').tableExport({
						fileName: '<?php echo $caduser; ?>',
                        type: 'pdf',
						escape: 'false',
                        jspdf: {format: 'bestfit',
                                margins: {left:20, right:10, top:20, bottom:20},
								autotable: {styles: {fontSize: '14'},
											tableWidth: 'wrap'
										   }
                               }
                    });
					
		}
		
	    function SalvarDOC(){
			$('.SalvarTabela').tableExport({
				fileName: '<?php echo $caduser; ?>',
				type: 'doc',
				escape: 'false'
				})			
		}
		
		function SalvarExcel(){
			$('.SalvarTabela').tableExport({
				fileName: '<?php echo $caduser; ?>',
				type: 'xls',
				escape: 'false'
				})			
		}
		
		function SalvarPNG(){
			$('.SalvarTabela').tableExport({
				fileName: '<?php echo $caduser; ?>',
				type: 'png',
				escape: 'false'
				})			
		}
		</script>



<?php
}
}else{
	echo Redirecionar('index.php');
}
}else{
	echo Redirecionar('login.php');
}
?>