<?
include("../Librerias/ConfNivel2.inc");
$Nivel=$_Nivel2;
$ObjSesion=new Sesiones();   //Clase Sesin
$ObjSesion->MVerifica($Nivel);
$Conexion=new DBAccess();
$Conexion->Acceso($Servidor,$UsuarioBD,$ClaveBD,$BaseDatos);
$Formulario=new Formulario();
/*Obtenemos los valor por post*/
$tags2 = array_keys($_POST); // obtiene los nombres de las variables
$valores2 = array_values($_POST);// obtiene los valores de las variables
$i=0;
foreach ($_POST as $valores){
 ${$tags2[$i]}=$valores;
 $i++;	
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//ES" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
    <head> 
		<meta name="viewport" content="width=device-width, initial-scale=1, charset=ISO-8859-1">
		<link rel="stylesheet" type="text/css" href="<? echo $Nivel ?>bootstrap/css/bootstrap.css">

         <?

	   if ($_JQuery == 1)
echo '<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>';
else
echo '<script src="'.$Nivel.'bootstrap/js/jquery.min.js"></script>';
 echo "<link rel='stylesheet' type='text/css' media='all' href='".$Nivel."Scripts/calendar-blue.css' title='win2k-1' />";
        echo "<script type='text/javascript' src='".$Nivel."Scripts/calendar.js'></script>";
        echo "<script type='text/javascript' src='".$Nivel."Scripts/calendar-es.js'></script>";
        echo "<script type='text/javascript' src='".$Nivel."Scripts/funcionescalendario.js'></script>";
		echo "<script type='text/javascript' src='".$Nivel."Scripts/Validaciones.js'></script>";		
        echo "<script language='javascript'>var actual='$FechaActual';</script>";	

	   ?>
        <script src="<? echo $Nivel ?>bootstrap/js/bootstrap.min.js"></script>
        <link rel="stylesheet" type="text/css" href="<? echo $Nivel ?>Librerias/DataTables-1.10.13/media/css/jquery.dataTables.css">
     <script type="text/javascript" language="javascript" src="<? echo $Nivel ?>Librerias/DataTables-1.10.13/media/js/jquery.dataTables.js"></script>
        <link rel="stylesheet" href="<? echo $Nivel ?>Librerias/multicombos/chosen.css">	
         <style type="text/css" media="all">
				     .chosen-rtl .chosen-drop { left: -1000px; }
                  </style>
                   <style>
               #mdialTamanio{
                 width: 60% !important;
                   }					 
             </style>      		
		<title>Consultas</title>        
	</head>
	<body style="padding-top: 60px;">
    <?

include $Nivel."menu1.php";

?>

<div class="container">
 <div class="panel panel-primary sombras">
 <div class="titulo"><strong><i class="fa fa-search" aria-hidden="true"></i> Gestor de Consultas</strong></div>
  <div class="row" style="margin-left: 10px; margin-right: 10px; margin-top:10px; margin-bottom:10px">  
  <form id="Formulario" name="Formulario" method="Post" action="buscarcanto.php">
    <input name="IdBusqueda" type="hidden" id="IdBusqueda" value="<?php echo $IdBusqueda ?>" />
    <input name="Accion" type="hidden" value="" />
    <input name="camps" id="camps"  type="hidden" value="" />
    <input name="groups" id="groups"  type="hidden" value="" />
    <input name="groupsnum" id="groupsnum"  type="hidden" value="" />
    <input name="etifechas" id="etifechas"  type="hidden" value="0" />
  <div class="form-group col-sm-12">
  <label for="campos" class="col-md-6 control-label">Elige Tiempos Lit&uacute;rgicos </label>    
	  <select data-placeholder="Elija el tiempo lit&uacute;rgico" id="tiemposlit" name="tiemposlit[]" multiple class="chosen-select" tabindex="8">
            <option value=""></option>
              <? $seldir = "SELECT tiempolit, idtiempo FROM tiemposlit order by idtiempo Asc";
			$VarDire =$Conexion->MVectorRegistro($seldir);			
			while ($RenDir = mysqli_fetch_array($VarDire)){
			?>
            <option value=<? echo '"'.$RenDir["idtiempo"].'" '; if ($tiemposlit) {if (in_array($RenDir["idtiempo"], $tiemposlit)) echo " selected "; else "";} ?>><? echo $RenDir["tiempolit"]; ?></option>            
            <? }?>
          </select>	          
           </div>
           <?
		  
           ?>
           
   <div class="form-group col-sm-12">       
        <label for="Momentos" class="col-md-6 control-label">Elige Sugerencia de uso</label> 	
        <select data-placeholder="Elija la sugerencia de uso" id="Momentos" name="Momentos[]" multiple class="chosen-select" tabindex="8">
            <option value=""></option>
              <? $seldir = "SELECT IdMomento, Momento FROM momentos order by IdMomento Asc";
			$VarDire =$Conexion->MVectorRegistro($seldir);			
			while ($RenDir = mysqli_fetch_array($VarDire)){
			?>
            <option value=<? echo '"'.$RenDir["IdMomento"].'" '; if ($Momentos) {if (in_array($RenDir["IdMomento"], $Momentos)) echo " selected "; else "";}?>><? echo $RenDir["Momento"]; ?></option>            

            <? }?>

          </select>	     

      </div>     
      <div class="form-group col-sm-12"> 
        <label for="Etiqueta" class="col-md-12 control-label">Por Etiqueta </label>
       <?  $Formulario->MInputTexto("Etiqueta",$Seleccion,40,35,4,'Placeholder = "Buscar por etiqueta"',"form-control"); ?>
      </div>
      <br/> 
      <br/> 
      <br/> 
  <div class="row1" align="center">   
        <?php	
		   $EventoG='Busca()';
		   //$Formulario->MBotonScript("Buscar","",$EventoG,"4");
		   $Formulario->MBotonScript('Buscar','Buscar',$EventoG,"btn btn-info btn3d","fa fa-search");
			echo '<b>&nbsp;';
		   ?>     
    </div>
    </br>
  </form>
</div>
</div>
<div class="row" >
  <? 
  //echo "--> ".$Accion;
if ($Accion == 'Buscar'){ 
  $cadesql = " SELECT cantos.IdCanto,cantos.Titulo, autores.Nombres, autores.Apellidos, cantos.TiempoLit,
tiemposlit.tiempolit, momentos.Momento, momentos.IdMomento FROM cantos left JOIN autores ON cantos.IdAutorMusica = autores.IdAutor 
left JOIN tiemposlit ON cantos.TiempoLit = tiemposlit.idtiempo left JOIN momentos ON cantos.Momento = momentos.IdMomento where 1 ";     

if (!empty($tiemposlit))
$cadesql.= " And (cantos.TiempoLit in (".implode(",",$tiemposlit)."))";
if (!empty($Momentos))
$cadesql.= " And (cantos.Momento in (".implode(",",$Momentos)."))";
if (!empty($Etiqueta))
$cadesql.= ' And (cantos.Etiqueta like "%'.$Etiqueta.'%")';
//echo $cadesql;
		$RowDir=$Conexion->MVectorRegistro($cadesql);
		//Obtenemos el número de filas de la consulta
		$Numifilas = $RowDir->num_rows;
		if ($Numifilas > 0 ){ 		
		?>
    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="display nowrap" id="example">
	<thead>
          <tr bgcolor="<?php echo $_CCT_GRID?>" style="cursor:pointer;color:#FFF" > 
            <td width="40%" height="25" align="center"><strong><i class="fa fa-music" aria-hidden="true"></i> T&iacute;tulo</strong></td>
            <td width="20%" align="center" bgcolor="<?php echo $_CCT_GRID?>"><strong><i class="fa fa-user-secret" aria-hidden="true"></i> Autor</strong></td>
            <td width="20%" align="center" bgcolor="<?php echo $_CCT_GRID?>"><strong><i class="fa fa-calendar-check-o" aria-hidden="true"></i> Tiempo Lit&uacute;rgico</strong></td>
            <td width="20%" align="center" bgcolor="<?php echo $_CCT_GRID?>"><strong><i class="fa fa-microphone" aria-hidden="true"></i> Sugerencia</strong></td>
          </tr>
    </thead>
	<tbody>
      <?
	  while ($renglon = mysqli_fetch_array($RowDir)){
		  echo '<tr>';	
		  echo '<td><a href="cantospres.php?IdCanto='.$renglon["IdCanto"].'" title="Mostrar datos">'.$renglon["Titulo"].'</td>';
		  echo '<td>'.$renglon["Nombres"]." ".$renglon["Apellidos"].'</td>';
		  echo '<td>'.$renglon["tiempolit"].'</td>';
		  echo '<td>'.$renglon["Momento"].'</td>';
		  echo '</tr>';
		}
	  ?>
     </tbody>
    <tfoot>
      <tr>
        <td></td> 
        <td></td> 
        <td></td>    
        <td width="0%"></td>
      </tr>
    </tfoot>
</table>
<? }else{
   echo '<div align="center" class="alert alert-warning alert-dismissible" role="alert">
  <strong>Sin Datos</strong></div>';
}
}
?>

</div>



    

<div class="spacer"></div>
  <script src="<? echo $Nivel?>Librerias/multicombos/docsupport/prism.js" type="text/javascript" charset="utf-8"></script>        
  <script src="<? echo $Nivel?>Librerias/multicombos/chosen.jquery.js" type="text/javascript"></script>
<? 

    //llamamos a las funciones para las animaciones

	echo "<script type='text/javascript'>";
	echo "var config = {
      '.chosen-select'           : {},
      '.chosen-select-deselect'  : {allow_single_deselect:true},
      '.chosen-select-no-single' : {disable_search_threshold:10},
      '.chosen-select-no-results': {no_results_text:'?Sin resultados!'},
      '.chosen-select-width'     : {width:'100%'}
    }
	for (var selector in config) {
      $(selector).chosen({ width: '100%' });
    }";

	echo '</script>';
	
	function calcularvalor ($evaluar, $arreglo, $separador){
		$resultado = '';
		 $divide = explode($separador, $arreglo); 		
		foreach($divide as $valor) {
			if ($evaluar == $valor)
			 $resultado = ' Selected ';
		}		
		return $resultado;
	}
	?>

<!--<script type="text/javascript" language="javascript" src="<? //echo $Nivel ?>Librerias/DataTables-1.10.13/media/js/jquery.dataTables.js"></script>      
 <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css"/> -->
<link rel="stylesheet" type="text/css" href="<? echo $Nivel.'Librerias/DataTables-1.10.13/'; ?>extensions/Buttons/css/buttons.dataTables.min.css">
<!-- <script type="text/javascript" src="https://cdn.datatables.net/select/1.2.1/js/dataTables.select.min.js"></script> -->
<script type="text/javascript" src="<? echo $Nivel.'Librerias/DataTables-1.10.13/'; ?>extensions/Buttons/js/dataTables.buttons.min.js"></script>
<script type="text/javascript" src="<? echo $Nivel.'Librerias/DataTables-1.10.13/'; ?>extensions/Buttons/js/buttons.print.min.js"></script>
<script type="text/javascript" src="<? echo $Nivel.'Librerias/DataTables-1.10.13/'; ?>extensions/Buttons/js/buttons.html5.min.js"></script>
<script type="text/javascript" src="<? echo $Nivel.'Librerias/DataTables-1.10.13/'; ?>extensions/Buttons/js/jszip.min.js"></script>
 <script type="text/javascript" src="<? echo $Nivel.'Librerias/DataTables-1.10.13/'; ?>extensions/Buttons/js/pdfmake.min.js"></script>
<script type="text/javascript" src="<? echo $Nivel.'Librerias/DataTables-1.10.13/'; ?>extensions/Buttons/js/vfs_fonts.js"></script> 
<script type="text/javascript" language="javascript" class="init">
$(document).ready(function() {
	  $('#example').DataTable( {
        dom: 'Bfrtip',
        buttons: [
            'excel', 'pdf', 'print'
        ]
    } );
} );	
</script> 

<SCRIPT language="JavaScript" type="text/JavaScript">
function Campos(){
		document.getElementById("camps").value = '';
	var actual = document.getElementById('campos'); 
var cadenitas = ""; 
for ( var i = 0, l = actual.options.length, o; i < l; i++ )
{
  o = actual.options[i];
  if ( o.selected && o.value != "directorio.telefono" )
  {
 document.getElementById("camps").value += o.value;
   if (i < (l-1))
    document.getElementById("camps").value += ',';
  } 
  else{
   if ( o.selected && o.value == "directorio.telefono" )  
    document.getElementById("etifechas").value = 1;
  }
}
 var cadecampos = document.getElementById("camps").value;
var ultimcar = document.getElementById("camps").value;
if (ultimcar.substr(-1) == ',' )
 document.getElementById("camps").value = cadecampos.slice(0,-1);
}

function Grupos(){
		document.getElementById("groups").value = '';
	var actual = document.getElementById('IdGrupo'); 
   if (document.getElementById("groups").length > 0){
	 document.getElementById("groups").value = '(';
   }
for ( var i = 0, l = actual.options.length, o; i < l; i++ )
{
  o = actual.options[i];  
  if ( o.selected )
  {
 document.getElementById("groups").value += ' directorio.Grupo = ' +  o.value;
 document.getElementById("groupsnum").value += o.value;
   if (i < (l-1)){
    document.getElementById("groups").value += ' OR ';
	 document.getElementById("groupsnum").value += ',';
   }
  } 
}
 var cadegrupos = document.getElementById("groups").value;
//alert( cadegrupos.slice(0,-4));
var ultimcar = cadegrupos.substr(-3);
//alert(ultimcar);

if (ultimcar == 'OR '){
document.getElementById("groups").value = cadegrupos.slice(0,-3);
var comas = document.getElementById("groupsnum").value;
document.getElementById("groupsnum").value = comas.slice(0,-1);
}
if (document.getElementById("groups").length > 0){
document.getElementById("groups").value += ')';
}

//alert(document.getElementById("groupsnum").value);

}
///////////////////////////////////////////////////funcion de inserción
function Busca(){
  Formulario.Accion.value='Buscar';
  //alert( Formulario.Accion.value);
  Formulario.submit();
 //}
}//Fin Guarda
</script> 

