<?php

require_once "../../../app/model/db.class.php";

if ($_POST['accion']=='mostrar_tabla'){

    $cadena="<center><table border='0' cellspacing='5' cellpadding='0' width='100%'>";
    
    $cadena.="<tr>";
    $cadena.="<td><b>C&Oacute;DIGO</b>
              <INPUT style='font-weight:bold;text-align:center;' onblur='comprobar_codigo()' TYPE='TEXT' ID='codigo' SIZE='5'>";
    
    $cadena.="&ensp;&ensp;<b>NOMBRES</b>
              <INPUT  style='font-weight:bold;text-align:center;' TYPE='TEXT' ID='nombres' SIZE='50' readonly=\"readonly\">";
    
    $cadena.="&ensp;&ensp;<b>GRADO</b>";
    $cadena.="<input style='font-weight:bold;text-align:center;' type='text' id='gr_id1' size='2' readonly=\"readonly\">
              <input style='font-weight:bold;text-align:center;background-color: #dfdcdc' type='text' id='gr_id2' size='15' readonly=\"readonly\">";

    $cadena.="&ensp;&ensp;<b>CURSO</b>";
    $cadena.="<input style='font-weight:bold;text-align:center;' type='text' id='cur_id1' size='2' readonly=\"readonly\">
              <input style='font-weight:bold;text-align:center;background-color: #dfdcdc' type='text' id='cur_id2' size='15' readonly=\"readonly\"></td>";

    $cadena.="</tr><tr>";

    $cadena.="<td><b>PERIODO</b>";
    $cadena.="<input style='font-weight:bold;text-align:center;' onclick=\"mostrar('per_id1','per_id2','periodos',250,190);\" type='text' id='per_id1' size='2'>
              <input style='font-weight:bold;text-align:center;background-color: #dfdcdc' type='text' id='per_id2' size='15' readonly=\"readonly\">";

    $cadena.="&ensp;&ensp;<b>FECHA</b>
               <INPUT  style='font-weight:bold;text-align:center;' TYPE='TEXT' ID='fecha' SIZE='10' onkeyup ='this.value=this.value.toUpperCase()'>";
        
    $cadena.="&ensp;&ensp;<b>FALTA</b>";
    $cadena.="<input style='font-weight:bold;text-align:center;' onclick=\"mostrar('ft_id1','ft_id2','faltas',750,390);\" type='text' id='ft_id1' size='2'>
              <input style='font-weight:bold;background-color: #dfdcdc' type='text' id='ft_id2' size='75' readonly=\"readonly\"></td>";
    
    $cadena.="</tr><tr>";
             
    $cadena.="<td><b>OBSERVACI&Oacute;N</b>";
    $cadena.="&ensp;<input type='text' id='descrip' size='148'>";

    $cadena.="&ensp;&ensp;&ensp;<INPUT TYPE='button' name='btngrabar' onclick='Grabar();' value=' Grabar '><INPUT TYPE='button' name='btnlimpiar' onclick='Limpiar();' value=' Limpiar '></td></tr></table>";
    $cadena.="</center>	<div id='dialog' style='background-color:#003366; ' title='SELECCIONE ITEM' style=\"display:none;\"></div>";
    echo $cadena;

}


//------------------------------------

if ($_POST['accion']=='tablabuscarF'){

    $cadena="<center><br><table width='100%' border='0' cellspacing='0' cellpadding='0' '>

              <tr style='font-size:12px;'> 
              <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <b>PERIODO</b>
              <input style='font-weight:bold;text-align:center;' onclick=\"mostrar('per_id1','per_id2','periodos',250,190);\" type='text' id='per_id1' size='2'>
              <input style='color:#DF0101;font-weight:bold;text-align:center;background-color: #dfdcdc' type='text' id='per_id2' size='15' readonly=\"readonly\">
                    
              <b>FECHA</b>
              <INPUT  style='background-color:#F5A9BC;font-weight:bold;text-align:center;' TYPE='TEXT' ID='fecha' SIZE='10'>

              <b>GRADO</b>
              <input style='font-weight:bold;text-align:center;' onclick=\"mostrar_grados_profes('gra_id1','gra_id2',250,190);\" type='text' id='gra_id1' size='2'>
              <input style='color:#DF0101;font-weight:bold;text-align:center;background-color: #dfdcdc' type='text' id='gra_id2' size='15' readonly=\"readonly\">

              <b>CURSO</b>
              <input style='font-weight:bold;text-align:center;' onclick=\"mostrar_cursos_profes('cur_id1','cur_id2',250,190);\" type='text' id='cur_id1' size='2'>
              <input style='color:#DF0101;font-weight:bold;text-align:center;background-color: #dfdcdc' type='text' id='cur_id2' size='17' readonly=\"readonly\">

              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <INPUT TYPE='button' name='btnbuscar' class='button medium blue' onclick='Buscar();' value=' Mostrar '>
              <br>
 
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <b>ASIGNATURA</b>
              <input style='font-weight:bold;text-align:center;' onclick=\"mostrar_asign_profes('asign_id1','asign_id2',400,190);\" type='text' id='asign_id1' size='2'>
              <input style='color:#DF0101;font-weight:bold;text-align:center;background-color: #dfdcdc' type='text' id='asign_id2' size='40' readonly=\"readonly\">

              
              <b>C&Oacute;DIGO</b>
              <input style='background-color:#F5A9BC;font-weight:bold;text-align:center;' onblur=\"comprobar_codigo();\" type='text' id='codigo' size='5'>&nbsp;&nbsp;
              <input style='color:#DF0101;font-weight:bold;text-align:center;background-color: #dfdcdc' type='text' id='nombres' size='40' readonly=\"readonly\">
             
             &nbsp;&nbsp;&nbsp;
             <INPUT TYPE='button' name='btnlimpiar' class='button medium blue' onclick='LimpiarBus();' value='  Limpiar  '></td>
                                           
              </td>
              </tr>
              </table>";
             
    $cadena.="</center> <div id='dialog' style='background-color:#003366; ' title='SELECCIONE ITEM' style=\"display:none;\"></div>";
    
    echo $cadena;

}

//------------------------------------

if ($_POST['accion']=='grabar_perfalta'){

    $obj = new database();

    $codigo=$_POST['codigo'];
//    $fecha=cambiaf_a_mysql($_POST['fecha']);

    $fecha=$_POST['fecha'];
    $falta=$_POST['falta'];    
    $periodo=$_POST['periodo'];
    $descripcion=($_POST['descripcion']);
    $nota=$_POST['nota'];

        
    $obj->conectar(); $obj->consulta("set names 'utf8'");
    
    $resultado1=$obj->consulta("select codigo,fecha,falta,periodo from reporte_faltas where codigo='".$codigo."' and fecha='".$fecha."' and falta='".$falta."' and periodo='".$periodo."'");
    $obj->disconnect();

    $n=$obj->numero_de_filas($resultado1);


                                                                                                      
    $resultado=$obj->consulta("insert into reporte_faltas (codigo,fecha,falta,periodo,descripcion,descuento,estilo) values('".$codigo."','".$fecha."','".$falta."','".$periodo."','".$descripcion."',".$nota.",'ALUMNO')");

        if($resultado)
           echo "Registro Grabado";
        


    $obj->disconnect();

    }


//------------------------------------

if ($_POST['accion']=='actualizar_perfalta'){

    $obj = new database();

    $codigo=$_POST['codigo'];
    $fecha=$_POST['fecha'];
    $falta=$_POST['falta'];    
    $periodo=$_POST['periodo'];
    $descripcion= ($_POST['descripcion']);
    $nota=$_POST['nota'];
    $sec=$_POST['sec'];

    $obj->conectar(); $obj->consulta("set names 'utf8'");
    $resultado=$obj->consulta("update reporte_faltas set codigo='".$codigo."',fecha='".$fecha."',falta='".$falta."',periodo='".$periodo."',descripcion='".$descripcion."',descuento=".$nota."  where orden=".$sec."");
    
    $obj->disconnect();

    if($resultado){
       echo "Falta Actualizada";
    }
}

//------------------------------------

if ($_POST['accion']=='borrar_faltaPer'){

    $obj = new database();

    $codigo=$_POST['codigo'];
    $obj->conectar(); $obj->consulta("set names 'utf8'");

    $resultado1=$obj->consulta("delete from reporte_faltas where orden='".$codigo."'");

       if($resultado1){
          echo "Falta Eliminada";
       }
    

    $obj->disconnect();

}

//------------------------------------

if ($_POST['accion']=='editar_faltaPer'){

    $obj = new database();

    $codigo=$_POST['codigo'];
    $obj->conectar(); $obj->consulta("set names 'utf8'");

    $query=$obj->consulta("select * from reporte_faltas where orden='".$codigo."'");
        
    $obj->disconnect();
    $row = $obj->fetch_assoc($query);

   $resultado=$obj->consulta("select matriculas.codigo,CONCAT(p_apellido,' ',s_apellido,' ',p_nombre,' ',s_nombre) as nombres,matriculas.estado, matriculas.grado, grados.descripcion as nom_grad, matriculas.curso, cursos.descripcion as nom_cur
               from (grados inner join (cursos inner join matriculas on (cursos.codigo = matriculas.curso) and (cursos.grado = matriculas.grado)) on grados.codigo = cursos.grado) inner join alumnos on matriculas.codigo = alumnos.codigo
               where  matriculas.codigo='".$row['codigo']."'");

    $row1=$obj->fetch_assoc($resultado);

    $cadena="<center><table border='0' cellspacing='5' cellpadding='0' width='100%'>";

    $cadena.="<tr style='font-weight:bold;font-size:12px;'>";
    $cadena.="<td><b>C&Oacute;DIGO</b>
              <INPUT style='font-weight:bold;text-align:center;font-size:12px;' VALUE='".$row['codigo']."' TYPE='TEXT' ID='codigo' SIZE='5'>";

    $cadena.="&ensp;&ensp;<b>NOMBRES</b>
              <INPUT  style='font-weight:bold;text-align:center;font-size:12px;' TYPE='TEXT' ID='nombres' VALUE='".($row1['nombres'])."' SIZE='40' readonly=\"readonly\">";

    $cadena.="&ensp;&ensp;<b>GRADO</b>";
    $cadena.="<input style='font-weight:bold;text-align:center;' type='text' id='gr_id1'  VALUE='".$row1['grado']."' size='2' readonly=\"readonly\">
              <input style='font-weight:bold;text-align:center;background-color: #dfdcdc;font-size:12px;' type='text' id='gr_id2' VALUE='".($row1['nom_grad'])."' size='15' readonly=\"readonly\">";

    $cadena.="&ensp;&ensp;<b>CURSO</b>";
    $cadena.="<input style='font-weight:bold;text-align:center;' type='text' id='cur_id1' VALUE='".$row1['curso']."' size='2' readonly=\"readonly\">
              <input style='font-weight:bold;text-align:center;background-color: #dfdcdc;font-size:12px;' type='text' id='cur_id2' VALUE='".($row1['nom_cur'])."' size='15' readonly=\"readonly\"></td>";

    $cadena.="</tr><tr style='font-weight:bold;font-size:12px;'>";


    $resultado1=$obj->consulta("select * from periodos where  codigo='".$row['periodo']."'");
    $row2=$obj->fetch_assoc($resultado1);


    $cadena.="<td><b>PERIODO</b>";
    $cadena.="<input style='font-weight:bold;text-align:center;' onclick=\"mostrar('per_id1','per_id2','periodos',250,190);\" type='text' id='per_id1' VALUE='".$row['periodo']."' size='2'>
              <input style='font-weight:bold;text-align:center;background-color: #dfdcdc;font-size:12px;' type='text' id='per_id2' VALUE='".($row2['descripcion'])."' size='20' readonly=\"readonly\">";

    $cadena.="&ensp;&ensp;<b>FECHA</b>
               <INPUT  style='font-weight:bold;text-align:center;;font-size:12px;' TYPE='TEXT' ID='fecha' VALUE='".$row['fecha']."' SIZE='10'>";


    $resultado2=$obj->consulta("select * from faltas where  codigo='".$row['falta']."'");
    $row3=$obj->fetch_assoc($resultado2);


    $cadena.="&ensp;&ensp;<b>FALTA</b>";
    $cadena.="<input style='font-weight:bold;text-align:center;font-size:12px;' onclick=\"mostrar('ft_id1','ft_id2','faltas',750,390);\" type='text' id='ft_id1' VALUE='".$row['falta']."' size='2'>
              <input style='font-weight:bold;background-color: #dfdcdc;font-size:10px;' type='text' id='ft_id2' VALUE='".($row3['descripcion'])."' size='70' readonly=\"readonly\"></td>";

    $cadena.="</tr><tr>";

    $cadena.="<td><b>OBSERVACI&Oacute;N</b>";
    $cadena.="&ensp;<input style='font-weight:bold;font-size:10px;' type='text' id='descrip' VALUE='".($row['descripcion'])."' size='115'>";

    $cadena.="&ensp;<INPUT TYPE='button' name='btngrabar' onclick='Actualizar(".$row['orden'].");' value=' Grabar '><INPUT TYPE='button' name='btnlimpiar' onclick='Limpiar();' value=' Limpiar '></td></tr></table>";
    $cadena.="</center>	<div id='dialog' style='background-color:#003366; ' title='SELECCIONE ITEM' style=\"display:none;\"></div>";
    echo $cadena;

}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

if ($_POST['accion']=='editar_faltaPerBus'){

    $obj = new database();

    $codigo=$_POST['codigo'];
    $inicio=$_POST['inicio'];

    $obj->conectar(); $obj->consulta("set names 'utf8'");

    $query=$obj->consulta("select * from reporte_faltas where orden='".$codigo."'");

    $obj->disconnect();
    $row = $obj->fetch_assoc($query);

   $resultado=$obj->consulta("select matriculas.codigo,CONCAT(p_apellido,' ',s_apellido,' ',p_nombre,' ',s_nombre) as nombres,matriculas.estado, matriculas.grado, grados.descripcion as nom_grad, matriculas.curso, cursos.descripcion as nom_cur
               from (grados inner join (cursos inner join matriculas on (cursos.codigo = matriculas.curso) and (cursos.grado = matriculas.grado)) on grados.codigo = cursos.grado) inner join alumnos on matriculas.codigo = alumnos.codigo
               where  matriculas.codigo='".$row['codigo']."'");

    $row1=$obj->fetch_assoc($resultado);

    $cadena="<center><table border='0' cellspacing='5' cellpadding='0' width='100%'>";

    $cadena.="<tr style='font-size:11px;font-weight:bold;'>";
    $cadena.="<td><b>C&Oacute;DIGO</b>
              <INPUT style='font-size:10px;font-weight:bold;text-align:center;' VALUE='".$row['codigo']."' TYPE='TEXT' ID='codigo' SIZE='2'>";

    $cadena.="&ensp;<b>NOMBRES</b>
              <INPUT  style='font-size:10px;font-weight:bold;text-align:center;' TYPE='TEXT' ID='nombres' VALUE='".($row1['nombres'])."' SIZE='30' readonly=\"readonly\">";

    $cadena.="&ensp;<b>GRADO</b>";
    $cadena.="<input style='font-size:10px;font-weight:bold;text-align:center;' type='text' id='gr_id1'  VALUE='".$row1['grado']."' size='2' readonly=\"readonly\">
              <input style='font-size:10px;font-weight:bold;text-align:center;background-color: #dfdcdc' type='text' id='gr_id2' VALUE='".($row1['nom_grad'])."' size='8' readonly=\"readonly\">";

    $cadena.="&ensp;<b>CURSO</b>";
    $cadena.="<input style='font-size:10px;font-weight:bold;text-align:center;' type='text' id='cur_id1' VALUE='".$row1['curso']."' size='2' readonly=\"readonly\">
              <input style='font-size:10px;font-weight:bold;text-align:center;background-color: #dfdcdc' type='text' id='cur_id2' VALUE='".($row1['nom_cur'])."' size='8' readonly=\"readonly\">";

    $resultado1=$obj->consulta("select * from periodos where  codigo='".$row['periodo']."'");
    $row2=$obj->fetch_assoc($resultado1);


    $cadena.="<b>PERIODO</b>";
    $cadena.="<input style='font-size:10px;font-weight:bold;text-align:center;' onclick=\"mostrar('per_id1','per_id2','periodos',250,190);\" type='text' id='per_id1' VALUE='".$row['periodo']."' size='2'>
              <input style='font-size:10px;font-weight:bold;text-align:center;background-color: #dfdcdc' type='text' id='per_id2' VALUE='".($row2['descripcion'])."' size='8' readonly=\"readonly\">";

    $cadena.="&ensp;<b>FECHA</b>
              <INPUT  style='font-size:10px;font-weight:bold;text-align:center;' TYPE='TEXT' ID='fecha' VALUE='".$row['fecha']."' SIZE='8'></td>";

    $cadena.="</tr><tr style='font-size:11px;font-weight:bold;'><td>";


    $resultado2=$obj->consulta("select * from faltas where  codigo='".$row['falta']."'");
    $row3=$obj->fetch_assoc($resultado2);


    $cadena.="<b>FALTA</b>";
    $cadena.="<input style='font-size:10px;font-weight:bold;text-align:center;' onclick=\"mostrar('ft_id1','ft_id2','faltas',750,390);\" type='text' id='ft_id1' VALUE='".$row['falta']."' size='2'>
              <input style='font-size:10px;font-weight:bold;background-color: #dfdcdc' type='text' id='ft_id2' VALUE='".($row3['descripcion'])."' size='115' readonly=\"readonly\">
              <b>DESCONTAR NOTA</b>
              <input style='font-size:10px;font-weight:bold;text-align:center;font-size:10px' type='text' VALUE='".$row['descuento']."' id='nota' size='5'>              
              </td>";

    $cadena.="</tr><tr style='font-size:11px;font-weight:bold;'>";

    $cadena.="<td><b>OBSERVACI&Oacute;N</b>";
    $cadena.="&ensp;<input type='text' id='descrip' VALUE='".($row['descripcion'])."' size='100'>";

    $cadena.="&ensp;&ensp;&ensp;<INPUT TYPE='button' name='btngrabar' onclick='ActualizarBus(".$row['orden'].",".$inicio.");' value=' Actualizar '><INPUT TYPE='button' name='btnlimpiar' onclick='Limpiar();' value=' Limpiar '></td></tr></table>";
    $cadena.="</center>	<div id='dialog' style='background-color:#003366; ' title='SELECCIONE ITEM' style=\"display:none;\"></div>";
    echo $cadena;

}


?>
