<?php

include '../conector.php';
session_start();
$men="";$val1="";$val2="";$val3="";$val4="";$cur1="";$cur2="";$cur3="";$cur4="";
$class1="";$class2="";$class3="";$class4="";$act1="";$act2="";$act3="";$act4="";$tbody="";$cuenta="";$res_cuenta="";$rs_cta="";

if(isset($_SESSION["user"]) && ($_SESSION["tipo"]=='R'||$_SESSION["tipo"]=='S'||$_SESSION["tipo"]=='B')){
$cuenta="select usuarios.id,usuarios.name
	from usuarios
	where name='".$_SESSION["user"]."'
	";
$res_cuenta=mysql_query($cuenta);
$rs_cta=mysql_fetch_array($res_cuenta);

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

 $select_pago="select  	id,
			estudiante,
			titulo,
			descripcion,
			valor,
			fecha,
			fecha_insert,
			estado,
			(select estudiante.nombre from estudiante where estudiante.estudiante_id=pagos.estudiante),
			(select curso.codigo from estudiante,curso where curso.curso_id=estudiante.curso_id and estudiante.estudiante_id=pagos.estudiante)
 			from pagos 
 			where estado in ('D','P') 
 			order by id";


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



 if($_POST['val1']==1||$_POST['val1']==2||$_POST['val1']==3||$_POST['val1']==4){


  $select_eventos="select evento.*,(select curso.nombre from curso where curso.curso_id=evento.curso) from evento where fecha_evento between '".$_POST['fecha_i1']."' and  '".$_POST['fecha_f1']."' order by fecha_evento desc";
  $res_select_eventos=mysql_query($select_eventos);
   $num_fil=mysql_num_rows($res_select_eventos);
  
  if($num_fil>0){
					
					$tbody="<tbody>";
					
					while($r_eve=mysql_fetch_array($res_select_eventos)){
					
					$tbody.="<tr role='row'><td>".date("d-m-Y", strtotime(substr($r_eve[2],0,10)))."</td><td>".$r_eve[1]."</td><td>".$r_eve[7]."</td><td>".$r_eve[6]."</td>
					</tr>
					";
					}$tbody.="
					<tr><td colspan=5></td></tr>
					</tbody>";
}
  
 
 }


}

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

 if($_POST['val2']==1){
  $class1="";
  $class2="class=\"active\"";
  $act1="";
  $act2=" active ";

	
		
		
	$insertar_pago='insert into evento (mensaje,fecha_evento,docente,curso,user,fecha_pub)
	values("'.$_POST['mensaje2'].'","'.$_POST['fecha2'].'","'.$rs_cta[0].'","'.$_POST['curso2'].'",1,now()
	)';
//echo $insertar_pago;
	if(mysql_query($insertar_pago)){
	$men="<div class=\"alert alert-success\">
                    <button type=\"button\" class=\"close\" data-dismiss=\"alert\">X</button>
                    Evento Insertado
			</div>";
	
	}else{
	$men="<div class=\"alert alert-danger\">
                    <button type=\"button\" class=\"close\" data-dismiss=\"alert\">X</button>
                    Error al insertar Registro. ".mysql_error()."
			</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\">
<link rel='stylesheet' href='../js/css/jquery-ui-1.9.2.custom.css' />	

    <title>Eventos</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 crea_evento(){
if(document.getElementById('mens').value==''){alert('Debe diligenciar Mensaje');return false;}
	else{document.getElementById('mensaje2').value=document.getElementById('mens').value;}
if(document.getElementById('fecha_p').value==''){alert('Debe diligenciar Fecha del Evento');return false;}
	else{document.getElementById('fecha2').value=document.getElementById('fecha_p').value;}
if(document.getElementById('curso').value=='XX'){alert('Debe seleccionar Curso');return false;}
	else{document.getElementById('curso2').value=document.getElementById('curso').value;}

	document.getElementById('val2').value=1;
	document.forms['crear_event'].submit();
}   

function buscar_even(){
if(document.getElementById('fecha_i').value==''||document.getElementById('fecha_f').value==''){alert('Debe seleccionar ambas fechas');return false;}
		else{
		document.getElementById('fecha_i1').value=document.getElementById('fecha_i').value;
		document.getElementById('fecha_f1').value=document.getElementById('fecha_f').value;
		}

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

}
function actualiza_obs(ide,est){
	document.getElementById('buscar1').value=est;
	if(document.getElementById('periodo_'+ide).value==''){alert('Debe seleccionar periodo');return false;}
		else{document.getElementById('periodo1').value=document.getElementById('periodo_'+ide).value}
	if(document.getElementById('fecha_'+ide).value==''){alert('Debe seleccionar fecha');return false;}
		else{document.getElementById('fecha1').value=document.getElementById('fecha_'+ide).value}
	if(document.getElementById('problema_'+ide).value==''){alert('Debe digitar problema');return false;}
		else{document.getElementById('problema1').value=document.getElementById('problema_'+ide).value}
	if(document.getElementById('correctivo_'+ide).value==''){alert('Debe digitar correctivo');return false;}
		else{document.getElementById('correctivo1').value=document.getElementById('correctivo_'+ide).value}				
	document.getElementById('obs1').value=ide;
	
	document.getElementById('val1').value=2;
	document.forms['listar_pago'].submit();
}
function borra_obs(ide,est){



if (confirm('Esta seguro que desea anular esta obs.?')) {	

document.getElementById('buscar1').value=est;
document.getElementById('obs1').value=ide;

	document.getElementById('val1').value=3;
	document.forms['listar_pago'].submit();


}
		else{return false;}



}
</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'>
             	          <span style='float:right;margin-right:10px; margin-top:15px' class='label label-success'><span class='glyphicon glyphicon-user'></span> ".$_SESSION["user"]."</span>
       </a>
      </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 \"><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 active\"><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\">Consultar Eventos</a></li>
	  <li $class2 ><a href=\"#profile\" data-toggle=\"tab\">Diligenciar</a></li>
	</ul>
	
	<!-- Tab panes -->

	<div class=\"tab-content\">
	<div class=\"tab-pane fade in $act2 \" id=\"profile\">
		<form name='crear_event' id='crear_event' method='post' action='eventos.php#profile' target='' >
		<input type='hidden' name='val2' id='val2' value='".$val2."'>	
		<input type='hidden' name='mensaje2' id='mensaje2' value='".$mensaje2."'>	
		<input type='hidden' name='fecha2' id='fecha2' value='".$fecha2."'>	
		<input type='hidden' name='curso2' id='curso2' value='".$curso2."'>			
		<input type='hidden' name='valor2' id='valor2' value='".$valor2."'>			
		<input type='hidden' name='estado2' id='estado2' value='".$estado2."'>
		<input type='hidden' name='periodo2' id='periodo2' value='".$periodo2."'>		
		<input type='hidden' name='fecha_p2' id='fecha_p2' value='".$fecha_p2."'>				
		<input type='hidden' name='abono2' id='abono2' value='".$abono2."'>			
		
		<div class=\"page\">
			<fieldset>
				<legend>
					<br><span class=\"glyphicon glyphicon-plus\"></span> Nuevo Evento.          
				</legend>			
			</fieldset>
		
		
		<div class='input' style='float:left;width: 140px;padding-top: 5px;padding-left: 10px;text-align: left;' >
			Mensaje&nbsp;
		  </div>
		 <div class='' >
		 <textarea id='mens' rows=\"3\" cols=\"100\" style='width:48%;margin-bottom: 10px' onclick='this.value=\"\"' class='form-control' value=''></textarea>
		 </div>
		 <div class='input' style='float:left;width: 140px;padding-top: 5px;padding-left: 10px;text-align: left;' >
			Fecha&nbsp;
		  </div>
		 <div class='input' >
		    <input id='fecha_p' name='fecha_p' type='date' class='form-control'  style='width:48%;margin-bottom: 10px'>
		 </div>
		
		 <div class='input' style='float:left;width: 140px;padding-top: 5px;padding-left: 10px;text-align: left;' >
			Curso&nbsp;
		  </div>
		 <div class='input' >
		    <select id='curso' name='curso' class='form-control'  style='width:48%;margin-bottom: 10px'>";
		    $sel_plan="select curso_id,codigo,nombre from curso where estado='A'  ";
		    $res_sel_plan=mysql_query($sel_plan);
		    
		    while($r_plan=mysql_fetch_array($res_sel_plan)){
		    
		    echo "<option value=".$r_plan[0].">".$r_plan[1]." - ".$r_plan[2]."</option>";
		    
		    
		    
		    }
		    
		    
echo		    "</select>
		 </div>
		
		<fieldset>
		<legend>
					<br>
					
		</legend>	
			<button type='button' class='btn btn-info' onclick='crea_evento()'> Publicar</button>     
			<input type='reset' class='btn' value='Borrar'>
						
		</fieldset>
			
			<br>
		</div>
	</form>
</div>

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

	<input type='hidden' name='val1' id='val1' value='".$val1."'>	
<input type='hidden' name='buscar1' id='buscar1' value='".$buscar1."'>	
		<input type='hidden' name='titulo1' id='titulo1' value='".$titulo1."'>	
		<input type='hidden' name='descripcion1' id='descripcion1' value='".$descripcion1."'>			
		<input type='hidden' name='valor1' id='valor1' value='".$valor1."'>			
		<input type='hidden' name='estado1' id='estado1' value='".$estado1."'>
		<input type='hidden' name='fecha_i1' id='fecha_i1' value='".$fecha_i1."'>
		<input type='hidden' name='fecha_f1' id='fecha_f1' value='".$fecha_f1."'>		
		<input type='hidden' name='pago1' id='pago1' value='".$pago1."'>		
		<input type='hidden' name='abono1' id='abono1' value='".$abono1."'>					
		<input type='hidden' name='saldo1' id='saldo1' value='".$saldo1."'>
		<input type='hidden' name='abono_c' id='abono_c' value='".$abono_c."'>
		<input type='hidden' name='fecha_c' id='fecha_c' value='".$fecha_c."'>		
		<input type='hidden' name='pago_c' id='pago_c' value='".$pago_c."'>				

		<input type='hidden' name='periodo1' id='periodo1' value='".$periodo1."'>
		<input type='hidden' name='fecha1' id='fecha1' value='".$fecha1."'>
		<input type='hidden' name='problema1' id='problema1' value='".$problema1."'>
		<input type='hidden' name='correctivo1' id='correctivo1' value='".$correctivo1."'>
		<input type='hidden' name='obs1' id='obs1' value='".$obs1."'>						

	<input type='hidden' name='cur1' id='cur1' value='".$cur1."'>	
		<fieldset>
			<legend><br><span class=\"glyphicon glyphicon-th-list\"></span> 
				Listado Eventos
			</legend>			
		</fieldset>
	</div>
	 <div class='input' style='float:left;width: 100px;padding-top: 5px;padding-left: 12px;text-align: left;' >
			Fecha Inicial:&nbsp;
	  </div>
	 <div class='input' style='padding-left:11px;'>
		    <input type='date' id='fecha_i' name='fecha_i' class='form-control' value='".$_POST['fecha_i1']."' style='width:30%;margin-bottom: 10px' onclick='this.value=\"\"'>
	 </div>

	 <div class='input' style='float:left;width: 100px;padding-top: 5px;padding-left: 12px;text-align: left;' >
			Fecha Final:&nbsp;
	  </div>
	 <div class='input' style='padding-left:11px;'>
		    <input type='date' id='fecha_f' name='fecha_f' class='form-control' value='".$_POST['fecha_f1']."' style='width:30%;margin-bottom: 10px' onclick='this.value=\"\"'>
		 <button type='button' class='btn btn-info btn-sm' onclick='buscar_even()' style='margin-left: 10px'> Buscar</button>    
	 </div>

	<fieldset>
	<div class='table-responsive'>
	<table class='table table-striped table-bordered ' style='font-size:11px'>
		<thead>";
if(isset($r_est[0])&&!empty($r_est[0])){		
echo "<tr role='row'><td colspan='6'><h4>".$r_est[0]." - ".$r_est[1]."</h4></td></tr>";}
echo			"<tr role='row'>
				<th>Fecha Evento</th>
				<th>Mensaje</th>				
				<th>Curso</th>				
				<th>Fecha Pub.</th>
			</tr>
		</thead>";
		
echo $tbody;
echo	"
	</div>
	</table>
	</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=\"../js/jquery-ui-1.10.3.custom.js\"></script>
  
    <script src=\"../dist/js/bootstrap.min.js\"></script>
    <script src=\"../offcanvas.js\"></script>
<script>
      $(function() {
	$( \"#buscar\" ).autocomplete(
	{
		 source:'../source.php',		 
		 minLength: 3
	})
}); 
$(function() {
	$( \"#buscar_\" ).autocomplete(
	{	 source:'../source.php',		 
		 minLength: 3	})
}); 

function PrintContent(iden)
{
var DocumentContainer = document.getElementById('mimodala'+iden);
var WindowObject = window.open('', 'PrintWindow',
'width=750,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes');
WindowObject.document.writeln(DocumentContainer.innerHTML);
WindowObject.document.close();
WindowObject.focus();
       if (WindowObject.print()){ 
                WindowObject.close(); 
        }else{ 
                WindowObject.close(); 
        } 

//WindowObject.print();
//WindowObject.close();
}



</script>
  </body>
</html>
";
}else{
echo "<div align='center'>Debe registrase para usar la aplicaci&oacute;n <a href='index.php' > Registrar</a></div>";
}
?>