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

if(isset($_SESSION["user"])&& $_SESSION["tipo"]=='A'){

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

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

 if($_POST['val1']==1){
	if($_POST['estado1']=='A'){
	$cambiar_estado="update observacion set estado='I' where id=".$_POST['id1']." ";
	}
	if($_POST['estado1']=='I'){
	$cambiar_estado="update observacion set estado='A' where id=".$_POST['id1']." ";
	}
	
	if(mysql_query($cambiar_estado)){
	$men="<div class=\"alert alert-success\">
                    <button type=\"button\" class=\"close\" data-dismiss=\"alert\">X</button>
                    Estado Observaci&oacute;n Modificado
			</div>";
	}else{
	$men="<div class=\"alert alert-danger\">
                    <button type=\"button\" class=\"close\" data-dismiss=\"alert\">X</button>
			Error al Actualizar Estado de Observaci&oacute;n
			</div>";
	}
 }
 
  if($_POST['val1']==2){
 
$actualizar_obs="
	update observacion set
		tipo='".$_POST['tipo1']."',
		descripcion='".$_POST['desc1']."',
		fecha_insert=now(),
		estado='".$_POST['estado1']."'
	where id=".$_POST['id1']." ";
//echo $actualizar_obs."";
	if(mysql_query($actualizar_obs)){
	$men="<div class=\"alert alert-success\">
                    <button type=\"button\" class=\"close\" data-dismiss=\"alert\">X</button>
                    Observaci&oacute;n Modificada
			</div>";
	}else{
	$men="<div class=\"alert alert-danger\">
                    <button type=\"button\" class=\"close\" data-dismiss=\"alert\">X</button>
			Error al Actualizar Observaci&oacute;n
			</div>";
	}

 
 }
}


 $select_logro="select 
		 observacion.Id,
		 observacion.tipo,
		 observacion.descripcion,
		 observacion.fecha_insert,
		 observacion.estado
		 from observacion
		 order by observacion.tipo";
 $res_select_logro=mysql_query($select_logro);
//echo		$select_logro;		
					$tbody="<tbody>";
					while($r_slog=mysql_fetch_array($res_select_logro)){
					$c1='';$c2='';
					if($r_slog[4]=='A'){$est='Activo';$lab='success ';$c1=' selected ';}else{$est='Inactivo';$lab='danger ';$c2=' selected ';}
					
					
					if($r_slog[1]=='CE'){$tipo='Cumplimiento Escolar';}
					if($r_slog[1]=='CU'){$tipo='Cumplimiento';}					
					if($r_slog[1]=='PP'){$tipo='Presentaci&oacute;n Personal';}					
					$tbody.="<tr role='row'><td>".$r_slog[0]."</td><td>".$tipo."</td><td>".$r_slog[2]."</td><td><span class='label label-".$lab."'>".$est."</span> 
					</td>
					<td>
					<a class='btn btn-success btn-xs' name='".$r_slog[0]."' id='".$r_slog[0]."' onclick='cambiar_estado_obs(this.id,\"$r_slog[4]\")'>
                			<i class='glyphicon glyphicon-refresh icon-white'></i>  
			                Cambiar </a>
			                
			                <a class='btn btn-info btn-xs'  data-toggle='modal' data-target='#mimodala".$r_slog[0]."' onclick=''>
                			<i class='glyphicon glyphicon-edit icon-white'></i>  
			                Editar               
				        </a>
					</td>
					</tr>";
					
					
					
					$tbody.="<div name='mimodala".$r_slog[0]."' id='mimodala".$r_slog[0]."' class='modal fade bs-example-modal-sm' tabindex='-1' role='dialog' aria-labelledby='mySmallModalLabel' aria-hidden='true'>
						  <div class='modal-dialog modal-md'>
						    <div class='modal-content'>
						      <div class='modal-header'>
							      <button type='button' class='close' data-dismiss='modal' aria-hidden='true'>x</button>
						      		<h4 class='modal-title' id='myLargeModalLabel'>Consulta Logro</h4>
	      					      </div>
	      					      <div class='modal-body'>";
						$tbody.="
								 
					 <div class='input' style='float:left;width: 120px;padding-top: 5px;padding-left: 10px;text-align: left;height:20px;font-size:12px;' >
						Tipo &nbsp;  </div>
						<div class='input' >
						<select id='tipo_".$r_slog[0]."' name='tipo_".$r_slog[0]."' class='form-control2' style='width:50%;margin-bottom: 10px'>";
						$a1='';$a2='';$a3='';
						if($r_slog[1]=='CE'){$a1=' selected ';}
						if($r_slog[1]=='PP'){$a2=' selected ';}
						if($r_slog[1]=='CU'){$a3=' selected ';}						

						$tbody.="<option value='XX'>Seleccione Tipo</option>
						    	<option value='CE' $a1>Cumplimiento Escolar</option>
						    	<option value='PP' $a2>Presentaci&oacute;n Personal</option>
						    	<option value='CU' $a3>Cumplimiento</option>";
							
					$tbody.="</select>
						 </div>		 


						 <div class='input' style='float:left;width: 120px;padding-top: 5px;padding-left: 10px;text-align: left;height:20px;font-size:12px;' >
						Descripci&oacute;n &nbsp;  </div>
						<div class='input' ><input    value='".$r_slog[2]."' id='desc_".$r_slog[0]."' name='desc_".$r_slog[0]."' type='text' class='form-control2' style='width:50%;margin-bottom: 10px' >
						 </div>		 

				 	 <div class='input' style='float:left;width: 120px;padding-top: 5px;padding-left: 10px;text-align: left;height:20px;font-size:12px;' >
								Estado&nbsp;  </div>
					 <div class='input' >
								 <select id='estadoa".$r_slog[0]."' name='estadoa".$r_slog[0]."' class='form-control2' style='width:50%;margin-bottom: 10px'>
								 	<option value='A' $c1 >Activo</option>
								 	<option value='I' $c2 >Inactivo</option>
								 </select>
					 </div>	 ";

						 $tbody.="<div>
						 <button type=\"button\" class=\"btn btn-primary btn-xs\" onclick='actualizar_obs(".$r_slog[0].")' >Actualizar</button>
							<button type=\"button\" class=\"btn btn-info btn-xs\" data-dismiss='modal' >Cerrar</button>
							</div>";	
					
					
					
					
					
					
					
					
					}
					$tbody.="</tbody>";




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

 if($_POST['val2']==1){
  $class1="";
  $class2="class=\"active\"";
  $act1="";
  $act2=" active ";
		
/*
echo $_POST['nombre_registro2']." nombre_registro2<br>";
echo $_POST['docente2']." docente2<br>";
echo $_POST['asignatura2']." asignatura2<br>";
echo $_POST['pensum2']." pensum2<br>";
echo $_POST['periodo2']." periodo2<br>";
*/
/*
$select_curso="select curso_id from curso,pensum where curso.curso_id=pensum.class_id and pensum.subject_id=".$_POST['pensum2']." ";
$res_select_curso=mysql_query($select_curso);
$rs_curso=mysql_fetch_array($res_select_curso);*/

	$insertar_obs='insert into observacion (tipo,descripcion,fecha_insert)
	values("'.$_POST['l_tipo2'].'","'.$_POST['descripcion2'].'",now()
	)';

	if(mysql_query($insertar_obs)){
	$men="<div class=\"alert alert-success\">
                    <button type=\"button\" class=\"close\" data-dismiss=\"alert\">X</button>
                    Observaci&oacute;n Insertada
			</div>";
	}else{
	$men="<div class=\"alert alert-danger\">
                    <button type=\"button\" class=\"close\" data-dismiss=\"alert\">X</button>
			Error al Insertar Observaci&oacute;n
			</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>Observaciones Periodo</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 actualizar_obs(ide){

if(document.getElementById('tipo_'+ide).value=='XX'){alert('Debe seleccionar el Tipo de Observacion');return false;}
	else{document.getElementById('tipo1').value=document.getElementById('tipo_'+ide).value}

if(document.getElementById('desc_'+ide).value==''){alert('Debe digitar la descripcion');return false;}
	else{document.getElementById('desc1').value=document.getElementById('desc_'+ide).value}

document.getElementById('estado1').value=document.getElementById('estadoa'+ide).value;
document.getElementById('id1').value=ide;

	
	
	
	document.getElementById('val1').value=2;
	document.forms['listar_pensum'].submit();


}

function cambiar_estado_obs(id,est){

document.getElementById('id1').value=id;
document.getElementById('estado1').value=est;
	document.getElementById('val1').value=1;
	document.forms['listar_pensum'].submit();
}   

function crea_registro(){

	
if(document.getElementById('l_tipo').value=='XX'){alert('Debe seleccionar el Tipo de Observacion');return false;}
	else{document.getElementById('l_tipo2').value=document.getElementById('l_tipo').value}

if(document.getElementById('descripcion').value==''){alert('Debe digitar descripcion');return false;}
	else{document.getElementById('descripcion2').value=document.getElementById('descripcion').value}




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

function agregar(doc){

	var k,c;
	k=1;c=0;
	var mat= document.getElementById('l_materias');
	var m1 = document.createElement('option');
	mat.options.length=0;";
	$sel2='false';
	//	$sel2='';
	$TABLA_ASIG = mysql_query("SELECT * FROM pensum where estado='A' order by nombre");
		while($munic = mysql_fetch_array($TABLA_ASIG)) {
		echo   "if(doc ==$munic[3]) {";
				$municipios =mysql_query("SELECT * FROM asignatura where subject_id=$munic[4] order by  nombre");
				if(isset($municipios)){
				echo "mat.options[0] = new Option('Seleccione Materia...', 'XX', false, false);";  
					while($m12 = mysql_fetch_array($municipios)) {
				
						 echo "mat.options[k] = new Option('".$m12[2]."'+' - '+'".$munic[1]."' , '".$munic[0]."-".$munic[4]."',$sel2,$sel2);  
						 k++;";
					}
				}
			echo"}";
		}

echo	"}

</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 active\"><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=\"acudiente.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-user\"></span> Acudientes</a>                      
            <a href=\"asignaturas.php\" class=\"list-group-item\"><span class=\"glyphicon glyphicon-book\"></span> Asignaturas</a>
            <a href=\"cursos.php\" class=\"list-group-item\"><span class=\"glyphicon glyphicon-list\"></span> Cursos</a>
            <a href=\"pensum.php\" class=\"list-group-item\"><span class=\"glyphicon glyphicon-edit\"></span> Pensum</a>    
            <a href=\"logros.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-edit\"></span> Logros</a>                        
            <a href=\"observaciones.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-edit\"></span> Indicadores de Comportamiento</a>                                    
            <a href=\"horario.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-edit\"></span> Horario</a>
<a href=\"horario_atencion.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-edit\"></span> Horario de Atenci&oacute;n</a>            
<a href=\"planilla_asistencia.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-file\"></span> Control de Asistencia</a>            
<a href=\"planilla.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-file\"></span> Registro de Calificaciones</a>            
            <a href=\"planilla_obs.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-file\"></span> Observador del Estudiante</a>                        
            <a href=\"pagos.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-list\"></span> Pagos</a>                  
            <a href=\"reportes.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-file\"></span> Boletines</a>            
<a href=\"eventos.php\" class=\"list-group-item \"><span class=\"glyphicon glyphicon-edit\"></span> Anuncios</a>           
            <a href=\"config.php\" class=\"list-group-item\"><span class=\"glyphicon glyphicon-wrench\"></span> Configuraci&oacute;n</a>
          </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\">Indicadores</a></li>
	  <li $class2 ><a href=\"#profile\" data-toggle=\"tab\">Crear Indicador</a></li>
	</ul>
	
	<!-- Tab panes -->

	<div class=\"tab-content\">
	<div class=\"tab-pane fade in $act2 \" id=\"profile\">
		<form name='crear_pensum' id='crear_pensum' method='post' action='observaciones.php#profile' target='' >
		<input type='hidden' name='val2' id='val2' value='".$val2."'>	
		<input type='hidden' name='nombre_registro2' id='nombre_registro2' value='".$nombre_registro2."'>	
		<input type='hidden' name='descripcion2' id='descripcion2' value='".$descripcion2."'>
		<input type='hidden' name='l_tipo2' id='l_tipo2' value='".$l_tipo2."'>		
		<input type='hidden' name='asignatura2' id='asignatura2' value='".$asignatura2."'>				
		<input type='hidden' name='pensum2' id='pensum2' value='".$pensum2."'>						
		<input type='hidden' name='periodo2' id='periodo2' value='".$periodo2."'>
			
		<input type='hidden' name='id2' id='id2' value='".$id2."'>
		<input type='hidden' name='estado2' id='estado2' value='".$estado2."'>					

		<div class=\"page\">
			<fieldset>
				<legend>
					<br><span class=\"glyphicon glyphicon-plus\"></span> Nuevo Registro          
				</legend>			
			</fieldset>
		
		 <div class='input' style='float:left;width: 140px;padding-top: 5px;text-align: right;' >
			Tipo&nbsp;
		  </div>
		 <div class='input' >
		    <select id='l_tipo' name='l_tipo'  class='form-control' style='width:48%;margin-bottom: 10px'>
		    	<option value='XX' >Seleccione Tipo</option>
		    	<option value='CE' >Cumplimiento Escolar</option>
		    	<option value='PP' >Presentaci&oacute;n Personal</option>
		    	<option value='CU' >Cumplimiento</option>		    			    	
		    </select>		    
		 </div>
		 <div class='input' style='float:left;width: 140px;padding-top: 5px;text-align: right;' >
			Descripci&oacute;n&nbsp;
		  </div>
		 <div class='input' >
		    <input id='descripcion' name='descripcion' type='text' class='form-control' placeholder='' style='width:48%;margin-bottom: 10px'>
		 </div>
		
		<fieldset>
		<legend>
					<br>
					
		</legend>	
			<button type='button' class='btn btn-info' onclick='crea_registro()'> Crear Registro</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_pensum' id='listar_pensum' method='post' action='observaciones.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='id1' id='id1' value='".$id1."'>
	<input type='hidden' name='estado1' id='estado1' value='".$estado1."'>		
	<input type='hidden' name='tipo1' id='tipo1' value='".$tipo1."'>
	<input type='hidden' name='desc1' id='desc1' value='".$desc1."'>		
	
	
	
		<fieldset>
			<legend><br><span class=\"glyphicon glyphicon-th-list\"></span> 
				Listado          
			</legend>			
		</fieldset>
	</div>
	
	<fieldset>
	<div class='table-responsive'>
	<table id='observ' class='table  table-striped table-bordered  '>
		<thead>
			<tr role='row'>
				<th>Id</th>
				<th>Tipo</th>				
				<th>Descripci&oacute;n</th>				
				<th>Estado</th>								
				<th>&nbsp;</th>				
			</tr>
		</thead>";
		
echo $tbody;
echo	"
	</div>
	</table>
	</fieldset>
	
	
	
	</form>

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

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


</div><!--/row--></div><!--/row--><hr><footer><p>Todos los derechos reservados - Copyright &copy; 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>
    <script src='js/tablesort.min.js'></script>
    <script>
      new Tablesort(document.getElementById('observ'));
    </script>
  </body>
</html>
";
}else{
echo "<div align='center'>Debe registrase para usar la aplicaci&oacute;n <a href='index.php' > Registrar</a></div>";
} 
 ?>