<?php
include '../conector.php';
session_start();

if(isset($_SESSION["user"]) && ($_SESSION["tipo"]=='R'||$_SESSION["tipo"]=='S'||$_SESSION["tipo"]=='B')){
$cuenta="select docente.teacher_id,docente.coordinador
	from usuarios,docente 
	where name='".$_SESSION["user"]."'
	and usuarios.cuenta=docente.email";

$res_cuenta=mysql_query($cuenta);
$rs_cta=mysql_fetch_array($res_cuenta);

  $class1="class=\"active\"";
  $class2="";
  $act2="";
  $act1=" active ";


if(isset($_POST['val1'])&&!empty($_POST['val1'])){

 if($_POST['val1']==2){
$del_horario="delete from horario 
where id=".$_POST['horariob']." ";
//echo $del_horario;
mysql_query($del_horario)or die(mysql_error());
	$men="<div class=\"alert alert-success\">
                    <button type=\"button\" class=\"close\" data-dismiss=\"alert\">X</button>
                    Registro Borrado
			</div>";

 }

 if($_POST['val1']==1){
$act_horario="update horario set
curso='".$_POST['l_cursob']."',
asignatura='".$_POST['asignaturab']."',
dia=".$_POST['diasb'].",
hi=".$_POST['hib'].",
mi=".$_POST['mib'].",
hf=".$_POST['hfb'].",
mf=".$_POST['mfb'].",
fecha_modif=now()
where id=".$_POST['horariob']."
";
//echo $act_horario;
mysql_query($act_horario)or die(mysql_error());
	$men="<div class=\"alert alert-success\">
                    <button type=\"button\" class=\"close\" data-dismiss=\"alert\">X</button>
                    Horario Actualizado
			</div>";

 }
}






$select_curso="
SELECT curso_id,nombre,codigo
from curso 
where estado='A'"; 

					$res_select_curso=mysql_query($select_curso);


 $select_horario="select 
			 curso,asignatura,dia,hi,mi,hf,mf
			 from horario 
			 where horario.estado='A' order by dia";
			 $res_select_horario=mysql_query($select_horario);

				
//					$tbody.="<tr role='row'><td>".$r_sag[0]."</td><td>".$r_sag[1]."</td><td>".$r_sag[2]."</td><td>".$r_sag[3]."</td><td>".$r_sag[4]."</td><td>&nbsp;</td></tr>
					
				$tbody.="<div class='panel-group' id='accordion'>";
				while($r_cur=mysql_fetch_array($res_select_curso)){
				$tbody.="<div class='panel panel-default'>
					    <div class='panel-heading'>
					      <h4 class='panel-title'>
					        <a data-toggle='collapse' data-parent='#accordion' href='#collapseOne".$r_cur[0]."'>
					          <font size='2.5em'><b>Curso - ".$r_cur[1]."</b></font>
					        </a>
					      </h4>
					    </div>
					    <div id='collapseOne".$r_cur[0]."' class='panel-collapse collapse '>
					      <div class='panel-body'>
					      	<div class='table-responsive'>
					      	<table cellpadding='0' cellspacing='0' border='0' class='table table-striped table-bordered ' >
					      	 <tbody>	
					      ";
//table-normal
						//      for($i=1;$i<8;$i++){
						$tbody.="
							<tr>
								<td  align='center'><strong>Lunes</strong></td>
								<td  align='center'><strong>Martes</strong></td>								
								<td  align='center'><strong>Mi&eacute;rcoles</strong></td>
								<td  align='center'><strong>Jueves</strong></td>
								<td  align='center'><strong>Viernes</strong></td>

							<tr>	<td>";
//inicio ciclo						
						 $select_horario="
							 select * from 
							(
								(select  horario.curso, horario.asignatura, horario.dia, horario.hi, horario.mi, horario.hf, 
								horario.mf,horario.asignatura  as asig, horario.id, '' 
								from horario
								where horario.estado='A' 
								and horario.dia=1 
								and horario.curso=".$r_cur[0]." 
								and horario.asignatura in ('Descanso','Proyecto')
								)
								union
								(select  horario.curso, horario.asignatura, horario.dia, horario.hi, horario.mi, horario.hf, 
								horario.mf, asignatura.nombre  as asig, horario.id, docente.nombre 
								from horario,asignatura,docente 
								where horario.estado='A' 
								 and horario.dia=1
								 and horario.asignatura=asignatura.subject_id
								 and horario.curso=".$r_cur[0]."
								and docente.teacher_id=horario.docente 
								 )
								 ) a
								 order by a.dia,a.hi,a.mi
							 ";
							 //echo $select_horario."<br>";
							 $res_select_horario=mysql_query($select_horario);
						
							if(mysql_query($select_horario)){
							$num_hor=mysql_num_rows($res_select_horario);
							}
						
						if(isset($num_hor)&&$num_hor>0)	{
							
							while($r_selhor=mysql_fetch_array($res_select_horario)){	
							
							if($r_selhor[4]==0){$r_selhor[4]='00';}if($r_selhor[6]==0){$r_selhor[6]='00';}
							if($r_selhor[4]==5){$r_selhor[4]='05';}if($r_selhor[6]==5){$r_selhor[6]='05';}							
							$tbody.="
								<div class='btn-group dropup'>
								  <button type='button' class='btn btn-info btn-xs dropdown-toggle' data-toggle='dropdown' style='font-size:9px;margin-bottom:5px;'>
								    ".$r_selhor[7]."<br>( ".$r_selhor[3].":".$r_selhor[4]." - ".$r_selhor[5].":".$r_selhor[6]." )<br>$r_selhor[9]
								  </button>
								</div>
								<br>
								
								";

							 }
							} 
						$tbody.="</td><td>";							
//fin ciclo	
//inicio ciclo						
						$select_horario="
							 select * from 
							(
								(select  horario.curso, horario.asignatura, horario.dia, horario.hi, horario.mi, horario.hf, 
								horario.mf,horario.asignatura  as asig, horario.id, '' 
								from horario
								where horario.estado='A' 
								and horario.dia=2 
								and horario.curso=".$r_cur[0]." 
								and horario.asignatura in ('Descanso','Proyecto')
								)
								union
								(select  horario.curso, horario.asignatura, horario.dia, horario.hi, horario.mi, horario.hf, 
								horario.mf, asignatura.nombre  as asig, horario.id, docente.nombre 
								from horario,asignatura,docente 
								where horario.estado='A' 
								 and horario.dia=2
								 and horario.asignatura=asignatura.subject_id
								 and horario.curso=".$r_cur[0]."
								and docente.teacher_id=horario.docente 
								 )
								 ) a
								 order by a.dia,a.hi,a.mi
							 ";
							 //echo $select_horario."<br>";
							 $res_select_horario=mysql_query($select_horario);
						
							if(mysql_query($select_horario)){
							$num_hor=mysql_num_rows($res_select_horario);
							}
						
						if(isset($num_hor)&&$num_hor>0)	{
							
							while($r_selhor=mysql_fetch_array($res_select_horario)){	
							
							if($r_selhor[4]==0){$r_selhor[4]='00';}if($r_selhor[6]==0){$r_selhor[6]='00';}
							if($r_selhor[4]==5){$r_selhor[4]='05';}if($r_selhor[6]==5){$r_selhor[6]='05';}							
							$tbody.="
								<div class='btn-group dropup'>
								  <button type='button' class='btn btn-info btn-xs dropdown-toggle' data-toggle='dropdown' style='font-size:9px;margin-bottom:5px;'>
								    ".$r_selhor[7]."<br>( ".$r_selhor[3].":".$r_selhor[4]." - ".$r_selhor[5].":".$r_selhor[6]." )<br>$r_selhor[9]
								  </button>
								</div>
								<br>
								";

							 }
							} 
						$tbody.="</td><td>";	
//fin ciclo
//inicio ciclo						
						$select_horario="
							 select * from 
							(
								(select  horario.curso, horario.asignatura, horario.dia, horario.hi, horario.mi, horario.hf, 
								horario.mf,horario.asignatura  as asig, horario.id, '' 
								from horario
								where horario.estado='A' 
								and horario.dia=3 
								and horario.curso=".$r_cur[0]." 
								and horario.asignatura in ('Descanso','Proyecto')
								)
								union
								(select  horario.curso, horario.asignatura, horario.dia, horario.hi, horario.mi, horario.hf, 
								horario.mf, asignatura.nombre  as asig, horario.id, docente.nombre 
								from horario,asignatura,docente 
								where horario.estado='A' 
								 and horario.dia=3
								 and horario.asignatura=asignatura.subject_id
								 and horario.curso=".$r_cur[0]."
								and docente.teacher_id=horario.docente 
								 )
								 ) a
								 order by a.dia,a.hi,a.mi
							 ";
							 //echo $select_horario."<br>";
							 $res_select_horario=mysql_query($select_horario);
						
							if(mysql_query($select_horario)){
							$num_hor=mysql_num_rows($res_select_horario);
							}
						
						if(isset($num_hor)&&$num_hor>0)	{
							
							while($r_selhor=mysql_fetch_array($res_select_horario)){	
							
							if($r_selhor[4]==0){$r_selhor[4]='00';}if($r_selhor[6]==0){$r_selhor[6]='00';}
							if($r_selhor[4]==5){$r_selhor[4]='05';}if($r_selhor[6]==5){$r_selhor[6]='05';}							
							$tbody.="
								<div class='btn-group dropup'>
								  <button type='button' class='btn btn-info btn-xs dropdown-toggle' data-toggle='dropdown' style='font-size:9px;margin-bottom:5px;'>
								    ".$r_selhor[7]."<br>( ".$r_selhor[3].":".$r_selhor[4]." - ".$r_selhor[5].":".$r_selhor[6]." )<br>$r_selhor[9]
								  </button>
								</div>
								<br>
								
								";

							 }
							} 
						$tbody.="</td><td>";	
//fin ciclo
//inicio ciclo						
						$select_horario="
							 select * from 
							(
								(select  horario.curso, horario.asignatura, horario.dia, horario.hi, horario.mi, horario.hf, 
								horario.mf,horario.asignatura  as asig, horario.id, '' 
								from horario
								where horario.estado='A' 
								and horario.dia=4 
								and horario.curso=".$r_cur[0]." 
								and horario.asignatura in ('Descanso','Proyecto')
								)
								union
								(select  horario.curso, horario.asignatura, horario.dia, horario.hi, horario.mi, horario.hf, 
								horario.mf, asignatura.nombre  as asig, horario.id, docente.nombre 
								from horario,asignatura,docente 
								where horario.estado='A' 
								 and horario.dia=4
								 and horario.asignatura=asignatura.subject_id
								 and horario.curso=".$r_cur[0]."
								and docente.teacher_id=horario.docente 
								 )
								 ) a
								 order by a.dia,a.hi,a.mi
							 ";
							 //echo $select_horario."<br>";
							 $res_select_horario=mysql_query($select_horario);
						
							if(mysql_query($select_horario)){
							$num_hor=mysql_num_rows($res_select_horario);
							}
						
						if(isset($num_hor)&&$num_hor>0)	{
							
							while($r_selhor=mysql_fetch_array($res_select_horario)){	
							
							if($r_selhor[4]==0){$r_selhor[4]='00';}if($r_selhor[6]==0){$r_selhor[6]='00';}
							if($r_selhor[4]==5){$r_selhor[4]='05';}if($r_selhor[6]==5){$r_selhor[6]='05';}							
							$tbody.="
								<div class='btn-group dropup'>
								  <button type='button' class='btn btn-info btn-xs dropdown-toggle' data-toggle='dropdown' style='font-size:9px;margin-bottom:5px;'>
								    ".$r_selhor[7]."<br>( ".$r_selhor[3].":".$r_selhor[4]." - ".$r_selhor[5].":".$r_selhor[6]." )<br>$r_selhor[9]
								  </button>
								</div>
								<br>
								
								";

							 }
							} 
						$tbody.="</td><td>";	
//fin ciclo
//inicio ciclo						
						$select_horario="
							 select * from 
							(
								(select  horario.curso, horario.asignatura, horario.dia, horario.hi, horario.mi, horario.hf, 
								horario.mf,horario.asignatura  as asig, horario.id, '' 
								from horario
								where horario.estado='A' 
								and horario.dia=5 
								and horario.curso=".$r_cur[0]." 
								and horario.asignatura in ('Descanso','Proyecto')
								)
								union
								(select  horario.curso, horario.asignatura, horario.dia, horario.hi, horario.mi, horario.hf, 
								horario.mf, asignatura.nombre  as asig, horario.id, docente.nombre 
								from horario,asignatura,docente 
								where horario.estado='A' 
								 and horario.dia=5
								 and horario.asignatura=asignatura.subject_id
								 and horario.curso=".$r_cur[0]."
								and docente.teacher_id=horario.docente 
								 )
								 ) a
								 order by a.dia,a.hi,a.mi
							 ";
							 //echo $select_horario."<br>";
							 $res_select_horario=mysql_query($select_horario);
						
							if(mysql_query($select_horario)){
							$num_hor=mysql_num_rows($res_select_horario);
							}
						
						if(isset($num_hor)&&$num_hor>0)	{
							
							while($r_selhor=mysql_fetch_array($res_select_horario)){	
							
							if($r_selhor[4]==0){$r_selhor[4]='00';}if($r_selhor[6]==0){$r_selhor[6]='00';}
							if($r_selhor[4]==5){$r_selhor[4]='05';}if($r_selhor[6]==5){$r_selhor[6]='05';}							
							$tbody.="
								<div class='btn-group dropup'>
								  <button type='button' class='btn btn-info btn-xs dropdown-toggle' data-toggle='dropdown' style='font-size:9px;margin-bottom:5px;'>
								    ".$r_selhor[7]."<br>( ".$r_selhor[3].":".$r_selhor[4]." - ".$r_selhor[5].":".$r_selhor[6]." )<br>$r_selhor[9]
								  </button>
								</div>
								<br>
								
								";

							 }
							} 
						$tbody.="</td>";	
//fin ciclo
//inicio ciclo					
						//$tbody.="<td>";		
						/*$select_horario="
							 select * from 
							(
								(select  horario.curso, horario.asignatura, horario.dia, horario.hi, horario.mi, horario.hf, 
								horario.mf,horario.asignatura  as asig, horario.id, '' 
								from horario
								where horario.estado='A' 
								and horario.dia=6 
								and horario.curso=".$r_cur[0]." 
								and horario.asignatura in ('Descanso','Proyecto')
								)
								union
								(select  horario.curso, horario.asignatura, horario.dia, horario.hi, horario.mi, horario.hf, 
								horario.mf, asignatura.nombre  as asig, horario.id, docente.nombre 
								from horario,asignatura,docente 
								where horario.estado='A' 
								 and horario.dia=6
								 and horario.asignatura=asignatura.subject_id
								 and horario.curso=".$r_cur[0]."
								and docente.teacher_id=horario.docente 
								 )
								 ) a
								 order by a.dia,a.hi,a.mi
							 ";
							 //echo $select_horario."<br>";
							 $res_select_horario=mysql_query($select_horario);
						
							if(mysql_query($select_horario)){
							$num_hor=mysql_num_rows($res_select_horario);
							}
						
						if(isset($num_hor)&&$num_hor>0)	{
							
							while($r_selhor=mysql_fetch_array($res_select_horario)){	
							
							if($r_selhor[4]==0){$r_selhor[4]='00';}if($r_selhor[6]==0){$r_selhor[6]='00';}
							if($r_selhor[4]==5){$r_selhor[4]='05';}if($r_selhor[6]==5){$r_selhor[6]='05';}							
							$tbody.="
								<div class='btn-group dropup'>
								  <button type='button' class='btn btn-info btn-xs dropdown-toggle' data-toggle='dropdown' style='font-size:9px;margin-bottom:5px;'>
								    ".$r_selhor[7]."<br>( ".$r_selhor[3].":".$r_selhor[4]." - ".$r_selhor[5].":".$r_selhor[6]." )<br>$r_selhor[9]
								  </button>
								</div>
								<br>
								
								";

							 }
							} */
	//					$tbody.="</td><td>";	
//fin ciclo

						//$tbody.="</td>";		
						$tbody.="						
							</tr>
							";	      
						    //  }
					      $tbody.="
					      	 </tbody>	
					      	</table>
					      	</div>
					      </div>
					    </div>
					  </div>";
				}
					$tbody.="</div>";








echo "
<!DOCTYPE html>
<html lang=\"en\">
  <head>
    <meta charset=\"utf-8\">
    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">
    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">
    <meta name=\"description\" content=\"\">
    <meta name=\"author\" content=\"\">
    <link rel=\"shortcut icon\" href=\"../assets/ico/favicon.ico\">
	<style>
	</style>
    <title>Horario</title>

    <!-- Bootstrap core CSS -->
    <link href=\"../dist/css/bootstrap.min.css\" rel=\"stylesheet\">

    <!-- Custom styles for this template -->
    <link href=\"../offcanvas.css\" rel=\"stylesheet\">

    <!-- Just for debugging purposes. Don't actually copy this line! -->
    <!--[if lt IE 9]><script src=\"../assets/js/ie8-responsive-file-warning.js\"></script><![endif]-->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src=\"https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js\"></script>
      <script src=\"https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js\"></script>
    <![endif]-->
    <script>
    function borra_horario(ide){
if (confirm('Esta seguro que desea borrar este registro?')) {	
document.getElementById('horariob').value=ide;	

	document.getElementById('val1').value=2;
	document.forms['listar_horario'].submit();
}
else{return false;}

}
function actualiza_horario(id){

if(document.getElementById('l_cursob'+id).value=='XX'){alert('Debe seleccionar el Curso');return false;}
	else{document.getElementById('l_cursob').value=document.getElementById('l_cursob'+id).value}
if(document.getElementById('asignaturab'+id).value=='XX'){alert('Debe seleccionar Asignatura');return false;}
	else{document.getElementById('asignaturab').value=document.getElementById('asignaturab'+id).value}
if(document.getElementById('diasb'+id).value=='XX'){alert('Debe seleccionar el Dia');return false;}
	else{document.getElementById('diasb').value=document.getElementById('diasb'+id).value}

if(document.getElementById('hib'+id).value=='XX'){alert('Debe seleccionar Hora Inicial');return false;}
	else{document.getElementById('hib').value=document.getElementById('hib'+id).value}
if(document.getElementById('mib'+id).value=='XX'){alert('Debe seleccionar Minuto Inicia');return false;}
	else{document.getElementById('mib').value=document.getElementById('mib'+id).value}
if(document.getElementById('hfb'+id).value=='XX'){alert('Debe seleccionar Hora Final');return false;}
	else{document.getElementById('hfb').value=document.getElementById('hfb'+id).value}
if(document.getElementById('mfb'+id).value=='XX'){alert('Debe seleccionar Minuto Final');return false;}
	else{document.getElementById('mfb').value=document.getElementById('mfb'+id).value}
document.getElementById('horariob').value=id;	

	document.getElementById('val1').value=1;
	document.forms['listar_horario'].submit();
	


}



</script>
  
    
    
    
  </head>

  <body>
    <div class=\"navbar navbar-fixed-top navbar-inverse\" role=\"navigation\">
      <div class=\"container\">

         
         <a class=\"\" href=\"general.php\"><img src='../img/logo1.png' style='margin-top:5px'></a>

        
        <a href=\"../index.php\"><img src='../img/salir.png' style='float:right;margin-top:15px'>
       </a><span style='float:right;margin-right:10px; margin-top:15px' class='label label-success'><span class='glyphicon glyphicon-user'></span> ".$_SESSION["user"]."</span>
      </div><!-- /.container -->
    </div><!-- /.navbar -->


    <div class=\"container\">

      <div class=\"row row-offcanvas row-offcanvas-left\">

       <div class=\"col-xs-6 col-sm-3 sidebar-offcanvas\" id=\"sidebar\" role=\"navigation\">
          <div class=\"list-group\">
            <a href=\"general.php\" class=\"list-group-item \" data-rel='popover' data-content='Dashboard' data-original-title><span class=\"glyphicon glyphicon-home\"></span> General</a>
            <a href=\"estudiantes.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-th\"></span> Estudiantes</a>
            <a href=\"docentes.php\" class=\"list-group-item\"><span class=\"glyphicon glyphicon-user\"></span> Docentes</a>
            <a href=\"horario.php\" class=\"list-group-item active\"><span class=\"glyphicon glyphicon-edit\"></span> Horario</a>            
            <a href=\"planilla.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-file\"></span> Planilla Notas</a>            
            <a href=\"planilla_obs.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-file\"></span> Planilla Obs.</a>
            <a href=\"reportes.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-file\"></span> Reportes</a>    
            <a href=\"pagos.php\" class=\"list-group-item\"><span class=\"glyphicon glyphicon-list\"></span> Pagos</a>
<a href=\"obs_disciplinarias.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-file\"></span> Obs. Disc.</a>                                
            	<a href=\"eventos.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-edit\"></span> Eventos</a>";                        
if($rs_cta[1]==1){
	echo	"<a href=\"obs_disciplinarias.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-file\"></span> Obs. Disc.</a>";
}
echo            
          "                        
          </div>
        </div><!--/span-->

        <div class=\"col-xs-12 col-sm-9\">
          <p class=\"pull-left visible-xs\">
            <button type=\"button\" class=\"btn btn-primary btn-xs\" data-toggle=\"offcanvas\">menu</button>
          </p>
    
	<div class=\"panel panel-default\">
	<br>";
echo $men;	
echo	      "
	      <!-- Nav tabs -->
	<ul class=\"nav nav-tabs\">
		<li >&nbsp;</li>
	  <li $class1 ><a href=\"#home\" data-toggle=\"tab\">Gestion de Horarios</a></li>
	</ul>
	
	<!-- Tab panes -->

	<div class=\"tab-content\">
	

<div class=\"tab-pane fade in $act1 \" id=\"home\">
	<form name='listar_horario' id='listar_horario' method='post' action='horario.php' target=''>
	<div class=\"page\">
	

	<input type='hidden' name='val1' id='val1' value='".$val1."'>	
	<input type='hidden' name='cur1' id='cur1' value='".$cur1."'>	
	<input type='hidden' name='l_cursob' id='l_cursob' value='".$l_cursob."'>		
	<input type='hidden' name='asignaturab' id='asignaturab' value='".$asignaturab."'>		
	<input type='hidden' name='diasb' id='diasb' value='".$diasb."'>		
	<input type='hidden' name='hib' id='hib' value='".$hib."'>		
	<input type='hidden' name='mib' id='mib' value='".$mib."'>		
	<input type='hidden' name='hfb' id='hfb' value='".$hfb."'>		
	<input type='hidden' name='mfb' id='mfb' value='".$mfb."'>	
	<input type='hidden' name='horariob' id='horariob' value='".$horariob."'>								
	
		<fieldset>
			<legend><br><span class=\"glyphicon glyphicon-calendar\"></span> 
				Horarios          
			</legend>			
		</fieldset>
	</div>
	<fieldset>
	<div class='table-responsive'>";
echo $tbody;
echo	"
	</div>
	</fieldset>
	</form>

</div>
 
         
        </div><!--/span-->

       
      </div><!--/row-->


      <footer>
        <p>&copy; Company 2022</p>
      </footer>

    </div><!--/.container-->

    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src=\"https://code.jquery.com/jquery-1.10.2.min.js\"></script>
    <script src=\"../dist/js/bootstrap.min.js\"></script>
    <script src=\"../offcanvas.js\"></script>
  </body>
</html>
";
}else{
echo "<div align='center'>Debe registrase para usar la aplicaci&oacute;n <a href='../index.php' > Registrar</a></div>";
}
?>