<?php

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

function descrip($tabla,$cod){
         $obj = new database();
         $obj->conectar(); $obj->consulta("set names 'utf8'");
         
         $result=$obj->consulta("select * from ".$tabla." where codigo='".$cod."';");
         $rs=$obj->fetch_assoc($result);
         $obj->disconnect();
         return $rs['descripcion'];
    }


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

    $asignatura=$_REQUEST['asignatura'];
    $periodo=$_REQUEST['periodo'];
    $grado=$_REQUEST['grado'];
    $curso=$_REQUEST['curso'];



        if($grado!='')//---grado
        {
            $v1="='".$grado."'";
        }else{
            $v1=" like '%' ";
        }


        if($curso!='')//---curso
        {
            $v2="='".$curso."'";
        }else{
            $v2=" like '%' ";
        }

        if($periodo!='')//---profesor
        {
            $v3="='".$periodo."'";
        }else{
            $v3=" like '%' ";
        }

        if($asignatura!='')//---asignatura
        {
            $v4="='".$asignatura."'";
        }else{
            $v4=" like '%' ";
        }

    $obj = new database();
    $obj->conectar(); $obj->consulta("set names 'utf8'");
    
    $resultado=$obj->consulta("select * from logros where grado ".$v1." and curso ".$v2." and asignatura ".$v4." and periodo ".$v3." order by orden asc;");
          
    $cadena="<center><br><table border='0' cellspacing='3' cellpadding='2' class='t_info'>";
    $cadena.="<tr>";

    $cadena.="<th>GRADO</th>";
    $cadena.="<th>CURSO</th>";
    $cadena.="<th>PERIODO</th>";
    $cadena.="<th>ASIGN.</th>";
    $cadena.="<th>C&Oacute;DIGO</th>";
    $cadena.="<th>DESCRIPCI&Oacute;N</th>";

    $cadena.="</tr>";
if($obj->numero_de_filas($resultado)!=0)
    {

    while ( $tsArray = $obj->fetch_assoc($resultado) )
            {
            $data[] = $tsArray;

            }

    for($i=0;$i<count($data);$i++){

        $cadena.="<tr>";

        $cadena.="<td align='center'>".$data[$i]['grado']."</td>";
        $cadena.="<td align='center'>".$data[$i]['curso']."</td>";
        $cadena.="<td align='center'>".$data[$i]['periodo']."</td>";
        $cadena.="<td align='center'>".$data[$i]['asignatura']."</td>";
        $cadena.="<td align='center'>".$data[$i]['codigo']."</td>";
        $cadena.="<td>".$data[$i]['descripcion']."</td>";

        $cadena.='<td align="center"> <img id="elemento1"  class="confirmar" src="imagenes/foto1.jpg" height="20" width="20"
                    onclick="eliminar('.$data[$i]['orden1'].')">  </td>';


        $cadena.='<td align="center"> <img id="elemento2"  class="confirmar" src="imagenes/editar.jpg" height="20" width="20"
                    onclick="editar('.$data[$i]['orden1'].')">  </td>';



        $cadena.="</tr>";
    }
    }else{
         $cadena.="<tr><td colspan='8' align='center'>Logros No Ingresados</td></tr>";
    }
    $cadena.="</table>";

    $cadena.="</center>";
    
    echo $cadena;

}

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


if($_REQUEST['accion']=='editar_logros_competencias'){

    $orden=$_REQUEST['orden'];

    $obj=new database();
    $obj->conectar(); $obj->consulta("set names 'utf8'");
    
    $result=$obj->consulta("select * from logros where orden1='".$orden."';");
    $obj->disconnect();
    $info='';
    if($obj->numero_de_filas($result))
        {
            $info[]=$obj->fetch_assoc($result);
        }

//    print_r($info);

    $cadena="".$info[0]['periodo'].";";
    $cadena.="".descrip('periodos',$info[0]['periodo']).";";

    $cadena.="".$info[0]['grado'].";";
    $cadena.="".descrip('grados',$info[0]['grado']).";";

    $cadena.="".$info[0]['curso'].";";
    $cadena.="".descrip('cursos',$info[0]['curso']).";";

    $cadena.="".$info[0]['asignatura'].";";
    $cadena.="".descrip('catalogo',$info[0]['asignatura']).";";

    $cadena.="".$info[0]['codigo'].";";
    $cadena.="".$info[0]['descripcion'].";";

    echo $cadena;
}


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


if($_REQUEST['accion']=='eliminar_logros_comp'){

    $orden=$_REQUEST['orden'];


    $obj=new database();
    $obj->conectar(); $obj->consulta("set names 'utf8'");
    
    $result=$obj->consulta("delete from logros where orden1='".$orden."' ;");
    $obj->disconnect();



    if($result){
        echo 'Registro Eliminado';
    }
}



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

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

    
    $per=$_REQUEST['per'];
    $grado=$_REQUEST['grado'];
    $curso=$_REQUEST['curso'];
    $asignatura=$_REQUEST['asignatura'];
    $codigo=$_REQUEST['codigo'];    
    $descrip=$_REQUEST['descrip'];
    $cod=$_REQUEST['codigo'];
    $ope=$_REQUEST['operacion'];

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

    if($ope=='x'){
        $resultado=$obj->consulta("select * from logros where grado='".$grado."' and curso='".$curso."' and asignatura='".$asignatura."' and periodo='".$per."' and codigo='".$cod."';");

        if($obj->numero_de_filas($resultado)==0)
        {

          $resultado=$obj->consulta("insert into logros (grado,curso,asignatura,periodo,codigo,descripcion,orden,orden1) values('".$grado."','".$curso."','".$asignatura."','".$per."','".$cod."','".$descrip."','".$cod."','');");

            $obj->disconnect();
            if($resultado){
               echo "1";
            }

        }else{
            echo "0";
        }
    }else{
        

         $result=$obj->consulta("update logros set  grado='".$grado."' ,
           curso='".$curso."' , periodo='".$per."' , asignatura='".$asignatura."' , codigo='".$codigo."', descripcion='".$descrip."', orden='".$codigo."' where orden1='".$ope."'");

         if($result)
            {
                echo '2';
            }
    }

    
    
}



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



if ($_POST['accion']=='reportes'){
    $cadena="  <div class='t'>REPORTE LOGROS</div>

<div  style=\"background-color:#000 ; width: 80%; margin: 5px 50px 5px 100px; padding: 2px 4px 2px 2px;\">
        <div id=\"report\"  style=\"background-color:#FAFAFA ; width: 100%;  padding: 20px 1px 20px 1px;\">

    <center><br><table border='0' cellspacing='2' cellpadding='2' >

    <tr>
    <td>
    <b>DOCENTE</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input style='font-weight:bold;text-align:center;' onclick=\"mostrardocente('d_id1','d_id2','profesores',400,280);\" type='text' id='d_id1' size='1'>
    <input style='font-weight:bold;background-color: #dfdcdc' type='text' id='d_id2' size='63' readonly=\"readonly\">
    </td>
    </tr>

    <tr>
    <td>

    <b>PERIODO</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input style='font-weight:bold;text-align:center;' onclick=\"mostrar('p_id1','p_id2','periodos',250,170);\" type='text' id='p_id1' size='1'>
    <input style='font-weight:bold;text-align:center;background-color: #dfdcdc' type='text' id='p_id2' size='13' readonly=\"readonly\">

    <b>GRADO</b>
    <input style='font-weight:bold;text-align:center;' onclick=\"mostrar('g_id1','g_id2','grados',250,310);\" type='text' id='g_id1' size='1'>
    <input style='font-weight:bold;text-align:center;background-color: #dfdcdc' type='text' id='g_id2' size='12' readonly=\"readonly\">

    <B>CURSO</B>
    <input style='font-weight:bold;text-align:center;' onclick=\"mostrarcurso('c_id1','c_id2','cursos',250,280);\" type='text' id='c_id1' size='2'>
    <input style='font-weight:bold;text-align:center;background-color: #dfdcdc' type='text' id='c_id2' size='15' readonly=\"readonly\">
  </td>
   </tr>

   <tr>
   <td>
    
    <b>ASIGNATURA</b>
    <input style='font-weight:bold;text-align:center;' onclick=\"mostrar('a_id1','a_id2','catalogo',450,380);\" type='text' id='a_id1' size='1'>
    <input style='font-weight:bold;background-color: #dfdcdc' type='text' id='a_id2' size='63' readonly=\"readonly\">
    </td>
    </tr>

    <tr>
    <td align='center'>
    <br>

    <input type='button' name='btnmostrar' onclick='pdf();' value=' Mostrar '>&nbsp;
    <input type='button' name='btnmostrar' onclick='limpiarpdf();' value=' Limpiar '>&nbsp;
    <input type='button' name='btnguardar' onclick='retroces();' value=' Retornar '>&nbsp;
    
    </td>
    </tr>
    </table>
   </center>

   <div id='dialog' style='background-color:#003366; ' title='SELECCIONE ITEM' style=\"display:none;\"></div>



        </div>
   </div>

";
    
    echo $cadena;

}


?>
